一直对/etc/shells这个文件的作用不是太清楚,最近抽时间查了查,总结如下。
- $ man shells
- SHELLS(5) Linux Programmer’s Manual SHELLS(5)
- NAME
- shells - pathnames of valid login shells
- DESCRIPTION
- /etc/shells is a text file which contains the full pathnames of valid login shells.
- This file is consulted by chsh(1) and available to be queried by other programs.
- Be aware that there are programs which consult this file to find out if a user is a
- normal user. E.g.: ftp daemons traditionally disallow access to users with shells
- not included in this file.
- EXAMPLE
- /etc/shells may contain the following paths:
- /bin/sh
- /bin/csh
- FILES
- /etc/shells
- SEE ALSO
- chsh(1), getusershell(3)
- 1993-11-21 SHELLS(5)
/etc/shells是一个有效登陆shell的列表,在调用chsh改变登陆shell时,会查询这个文件。
- [root@winway ~]# cat /etc/shells
- /bin/sh
- /bin/bash
- /sbin/nologin
- /bin/tcsh
- /bin/csh
- /bin/ksh
- [winway@winway ~]$ chsh
- Changing shell for winway.
- 口令:
- New shell [/bin/bash]: /bin/date
- chsh: "/bin/date" is not listed in /etc/shells.
- chsh: use -l option to see list
由于/bin/date/不在/etc/shells里,所以普通用户调用chsh失败。root调用会出现warning。
- [root@winway ~]# echo '/bin/date' >>/etc/shells
- [winway@winway ~]$ chsh -l
- /bin/sh
- /bin/bash
- /sbin/nologin
- /bin/tcsh
- /bin/csh
- /bin/ksh
- /bin/date
- [winway@winway ~]$ chsh
- Changing shell for winway.
- 口令:
- New shell [/bin/bash]: /bin/date
- Shell changed.
- [winway@winway ~]$ grep 'winway' /etc/passwd
-
winway:x:500:500:ww,isrc,no,no:/home/winway:/bin/date
另外一些程序会根据这个文件来判断一个用户是否是有效用户,例如FTP服务会阻止那些shell不在/etc/shells里的用户登陆。详见