菜鸟笔记
提升您的技术认知

Linux中的shell如何切换

在Linux中默认使用/bin/bash,在用户创建时,会自动给用户创建用户默认的shell

root     :x   :0  :0  :root   :/root    :/bin/bash 
注册用户名:密码:UID:GID:用户信息:用户主目录:命令解释程序 

如上,用于默认的shell就是/bin/bash。要修改shell将其设置为/bin/ksh,有两种方法方法

方法一: chsh -s /bin/ksh

[root@host ~]# chsh -s /bin/ksh           # 修改用户默认的shell为ksh
Changing shell for root.
Shell not changed.
[root@host ~]# egrep 'root' /etc/passwd   # 查看修改是否成功,按CTRL+D退出下次生效
root:x:0:0:root:/root:/bin/ksh 

方法二: usermod -s /bin/ksh root

[root@host ~]# usermod -s /bin/ksh root
 

其他命令或者相互操作:

查看当前使用的shell

[root@host ~]# echo $SHELL
/bin/bash
# 或者
[root@host ~]# egrep 'root' /etc/passwd
root:x:0:0:root:/root:/bin/bash 

查看所有可用的shell

[root@host ~]# cat /etc/shells
/bin/sh
/bin/bash
/bin/ksh
/bin/zsh
/bin/csh
......

# 或者

[root@host ~]# chsh -l
/bin/sh
/bin/bash
/bin/ksh
/bin/zsh
/bin/csh
......