/etc/shells文件用途

4580阅读 0评论2013-05-14 winway1988
分类:系统运维

一直对/etc/shells这个文件的作用不是太清楚,最近抽时间查了查,总结如下。

  1. $ man shells
  2. SHELLS(5) Linux Programmer’s Manual SHELLS(5)
  3. NAME
  4. shells - pathnames of valid login shells
  5. DESCRIPTION
  6. /etc/shells is a text file which contains the full pathnames of valid login shells.
  7. This file is consulted by chsh(1) and available to be queried by other programs.
  8. Be aware that there are programs which consult this file to find out if a user is a
  9. normal user. E.g.: ftp daemons traditionally disallow access to users with shells
  10. not included in this file.
  11. EXAMPLE
  12. /etc/shells may contain the following paths:
  13. /bin/sh
  14. /bin/csh
  15. FILES
  16. /etc/shells
  17. SEE ALSO
  18. chsh(1), getusershell(3)
  19. 1993-11-21 SHELLS(5)

/etc/shells是一个有效登陆shell的列表,在调用chsh改变登陆shell时,会查询这个文件。

  1. [root@winway ~]# cat /etc/shells
  2. /bin/sh
  3. /bin/bash
  4. /sbin/nologin
  5. /bin/tcsh
  6. /bin/csh
  7. /bin/ksh

  1. [winway@winway ~]$ chsh
  2. Changing shell for winway.
  3. 口令:
  4. New shell [/bin/bash]: /bin/date
  5. chsh: "/bin/date" is not listed in /etc/shells.
  6. chsh: use -l option to see list

       由于/bin/date/不在/etc/shells里,所以普通用户调用chsh失败。root调用会出现warning


  1. [root@winway ~]# echo '/bin/date' >>/etc/shells

  1. [winway@winway ~]$ chsh -l
  2. /bin/sh
  3. /bin/bash
  4. /sbin/nologin
  5. /bin/tcsh
  6. /bin/csh
  7. /bin/ksh
  8. /bin/date
  9. [winway@winway ~]$ chsh
  10. Changing shell for winway.
  11. 口令:
  12. New shell [/bin/bash]: /bin/date
  13. Shell changed.
  14. [winway@winway ~]$ grep 'winway' /etc/passwd
  15. winway:x:500:500:ww,isrc,no,no:/home/winway:/bin/date

另外一些程序会根据这个文件来判断一个用户是否是有效用户,例如FTP服务会阻止那些shell不在/etc/shells里的用户登陆。详见

上一篇:服务器批量管理工具
下一篇:关于fork以及子shell继承环境变量的疑问