一,/bin/false和/sbin/nologin作为shell时的区别
1,/bin/false
/bin/false
是一个什么都不做,立即返回非零退出状态的命令。它通常用于禁止用户登录
用户不会收到任何错误或提示信息,登录尝试简单地被拒绝,没有任何解释
2,/sbin/nologin
/sbin/nologin
是一个专门设计来阻止用户登录的程序。当被用作用户的登录shell时,它会显示一条拒绝登录的消息(通常是一行文本),然后结束会话
用户将看到一条消息(默认通常是“This account is currently not available.”)。这个消息可以通过编辑/etc/nologin.txt
文件来自定义
3, 应用范围:
/bin/false是最严格的禁止login选项,一切服务都不能用,而/sbin/nologin只是不允许系统login,还可以使用其他ftp等服务
二,用命令设置用户的shell
1,查看用户的shell
直接对/etc/passwd做grep
[root@web git]# grep git /etc/passwd
git:x:1002:1002::/home/git:/bin/bash
也可以用命令:lslogins
[root@web git]# lslogins git
Username: git
UID: 1002
Gecos field:
Home directory: /home/git
Shell: /bin/bash
No login: no
Password is locked: no
Password not required (empty): no
Login by password disabled: no
Password encryption method: SHA-512
Primary group: git
GID: 1002
Last login: Jul15/16:34
Last terminal: pts/0
Last hostname:
Hushed: no
Password expiration warn interval: 7
Password changed: Jul15/08:00
Maximum change time: 99999
Running processes: 0
Last logs:
Sep24/14:05 systemd[1570375]: Reached target Shutdown.
Sep24/14:05 systemd[1570375]: Finished Exit the Session.
Sep24/14:05 systemd[1570375]: Reached target Exit the Session.
也可以使用命令getent
[root@web git]# getent passwd git
git:x:1002:1002::/home/git:/bin/bash
2,设置用户shell为nologin
修改指定用户的shell
[root@web git]# usermod -s /sbin/nologin git
查看效果:
[root@web git]# lslogins git
Username: git
UID: 1002
Gecos field:
Home directory: /home/git
Shell: /sbin/nologin
No login: yes
Password is locked: no
Password not required (empty): no
Login by password disabled: no
Password encryption method: SHA-512
Primary group: git
GID: 1002
Last login: Jul15/16:34
Last terminal: pts/0
Last hostname:
Hushed: no
Password expiration warn interval: 7
Password changed: Jul15/08:00
Maximum change time: 99999
Running processes: 0
Last logs:
Sep24/14:05 systemd[1570375]: Reached target Shutdown.
Sep24/14:05 systemd[1570375]: Finished Exit the Session.
Sep24/14:05 systemd[1570375]: Reached target Exit the Session.
也可以直接查看passwd
[root@web git]# grep git /etc/passwd
git:x:1002:1002::/home/git:/sbin/nologin
3,设置用户shell也可以用chsh命令
[root@web git]# chsh -s /sbin/nologin git
Changing shell for git.
chsh: Warning: "/sbin/nologin" is not listed in /etc/shells.
Shell changed.
查看效果:
[root@web git]# grep git /etc/passwd
git:x:1002:1002::/home/git:/sbin/nologin
4,当然,直接编辑/etc/passwd也可以,但要注意不要误操作
标签:bin,sbin,git,nologin,shell,Password,1002 From: https://www.cnblogs.com/architectforest/p/18431044