chsh -s /bin/false user1
chsh -s /sbin/nologin
=> same behaviour, but differrent.
false -> reject to execute
nologin -> pam check and reject to login, then execute the message as below examples.
==================================
[root@rhel8-02 ~]# grep user1 /etc/passwd
user1:x:1001:1001::/home/user1:/sbin/nologin
[root@rhel8-02 ~]# su user1
This account is currently not available.
[root@rhel8-02 ~]#
[root@rhel8-02 ~]# chsh -s /bin/false user1
Changing shell for user1.
chsh: Warning: "/bin/false" is not listed in /etc/shells.
Shell changed.
[root@rhel8-02 ~]# grep user1 /etc/passwd
user1:x:1001:1001::/home/user1:/bin/false
[root@rhel8-02 ~]# su user1
[root@rhel8-02 ~]#
if we use nologin, it should be place in /etc folder and it will reject all users except root from logging in the system. But the question asks for "a user" not for all users, so we can change the path of bash shell in /etc/passwd file to /bin/false by using the command: chsh -s /bin/false username
"chsh -s /bin/false" is not correct, because chsh only cans change to a shell that is in the /etc/shells file, and /bin/false is not in this file, so if you execute this command you probably will get an error
from the NOTE section of the chsh man page ...
"The only restriction placed on the login shell is that the command name must be listed in /etc/shells, unless the invoker is the superuser, and then any value may be added."
So if the invoker is superuser or sudo is used this works. I have tried this with sudo and it works as intended.
yes, but in the /etc directory, not in the /home. so correct answer is chsh -s /bin/false
upvoted 4 times
...
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
bogvt
Highly Voted 2 years, 4 months agoJodelo
1 year agolucaverce
Most Recent 1 month, 3 weeks agoRoger95
8 months agoledlong
9 months, 3 weeks agogeorgerobel
1 year, 4 months agoEnemyTurret
1 year, 6 months agorjlg2centos8
1 year, 8 months agorjlg2centos8
1 year, 8 months agoNegator
1 year, 1 month ago3glag
2 years, 3 months agokatieK
2 years, 1 month ago