In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to prohibit users from logging in the Linux system, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Setting to disable shell login when creating a user
By default, when you create a user, the shell is assigned to the user as defined in the / etc/default/useradd file.
Linux comes with a / sbin/nologinshell that displays a message "This account is current not available" when the user tries to connect. This is one way to prevent users from logging in to shell. Here is how to use it:
Useradd-s / sbin/nologin {username}
For the following example, create a user with shell set to / sbin/nologin:
[root@localhost ~] # useradd user01-s / sbin/nologin [root@localhost ~] # tail-1 / etc/passwduser01:x:1000:1000::/home/user01:/sbin/nologin
Looking at / etc/passwd, you can see that the shell of user01 is / sbin/nologin
Set the password for the user01 user, and then test the ssh login:
[root@localhost ~] # echo '123' | passwd-- stdin user01Changing password for user user01.passwd: all authentication tokens updated successfully. [root@localhost ~] # ssh user01@localhostuser01@localhost's password:This account is currently not available.Connection to localhost closed.
After entering the password, prompt This account is current not available, and the connection is closed.
Set to disable shell login for existing users
To change the shell of an existing user, you can use the usermod and chsh commands to modify:
The syntax for the chsh command is as follows:
Chsh-s / sbin/nologin {username}
Modify the shell of the user02 user as follows:
# Centos8 does not install chsh by default. Use the following command to install: [root@localhost ~] # yum-y install util-linux-user [root@localhost ~] # chsh-s / sbin/nologin user02Changing shell for user02.chsh: Warning: "/ sbin/nologin" is not listed in/ etc/shells.Shell changed.
The syntax for the usermod command is as follows:
Usermod-s / sbin/nologin {username}
Modify the shell of the user03 user as follows:
[root@localhost] # usermod-s / sbin/nologin user03
You can also manually modify the user shell in the / etc/passwd file.
The above is all the contents of the article "how to prevent users from logging in in the Linux system". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.