linux更改用户登录shell


chsh就是change shell的简写,用来修改用户的登录shell,使用方法也很简单:
              [vbird1@study ~]$ chsh [-ls]
            
选项与参数:
-l :列出目前系统上面可用的shell ,其实就是/etc/shells的内容!
-s :修改用户的登录Shell。
范例一:用 vbird1 的身份列出系统上所有合法的 shell,并且指定 csh 为自己的 shell
-l选项可以列出系统中所有合法的shell,相当于显示/etc/shells文件中的内容:
[peter@study ~]$ chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
            
-s选项可以修改用户的登录shell,先观察一下peter的登录shell:
              [peter@study ~]$ grep peter /etc/passwd
              peter:x:1000:1000:peter,1920302,13861828579,13861828579:/home/peter:/bin/bash
            
可以看到peter的登录shell为/bin/bash,我们用-s选项将peter的登录shell修改为csh:
[peter@study ~]$ chsh -s /bin/csh; grep peter /etc/passwd
Password:
Changing shell for peter.
Shell changed.
peter:x:1000:1000:peter,1920302,13861828579,13861828579:/home/peter:/bin/dash
            
通过观察/etc/passwd文件可以看到登录shell变成/bin/dash了。
现在将登录shell改回/bin/bash:
[vbird1@study ~]$ chsh -s /bin/bash
            
这里介绍的chfn和chsh命令最终都会修改/etc/passwd文件, 而且是和passwd一样允许普通用户使用的账号管理命令。
但是我们知道普通用户无没有权限修改/etc/passwd文件的,所以其实chfn、chsh和passwd命令一样, 他们的可执行文件都具有特殊权限,都设置了有效用户id位:
              [root@study ~]$ ls -al $(which chfn)
              -rwsr-xr-x 1 root root 76496 Mar 23  2019 /usr/bin/chfn
              [root@study ~]$ ls -al $(which chsh)
              -rwsr-xr-x 1 root root 44528 Mar 23  2019 /usr/bin/chsh
              [root@study ~]$ ls -al $(which passwd)
              -rwsr-xr-x 1 root root 59640 Mar 23  2019 /usr/bin/passwd
            

initroot编辑整理,转载请注明www.initroot.com

100次点赞 100次阅读