Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
93 lines (65 loc) · 2 KB

File metadata and controls

93 lines (65 loc) · 2 KB
Copy raw file
Download raw file
Outline
Edit and raw actions

chsh

用来更换登录系统时使用的shell

补充说明

chsh命令 用来更换登录系统时使用的shell。若不指定任何参数与用户名称,则chsh会以应答的方式进行设置。

语法

chsh(选项)(参数)

选项

-s<shell 名称>或--shell<shell 名称>:更改系统预设的shell环境。;
-l或--list-shells:列出目前系统可用的shell清单;
-u或--help:在线帮助;
-v或-version:显示版本信息。

参数

用户名:要改变默认shell的用户。

实例

查看系统安装了哪些shell的两种方法:

第一种:

[rocrocket@localhost ~]$ chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh

第二种:

[rocrocket@localhost ~]$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh

其实chsh -l也是来查看这个文件。

查看当前正在使用的shell:

[rocrocket@localhost ~]$ echo $SHELL
/bin/bash

注意SHELL一定要是大写。可以看到,目前使用的shell是/bin/bash

把我的shell改成zsh:

[rocrocket@localhost ~]$ chsh -s /bin/zsh
Changing shell for rocrocket.
Password:
Shell changed.
[rocrocket@localhost ~]$

使用chsh加选项-s就可以修改登录的shell了!你会发现你现在执行echo $SHELL后仍然输出为/bin/bash,这是因为你需要重启你的shell才完全投入到zsh怀抱中去。chsh -s其实修改的就是/etc/passwd文件里和你的用户名相对应的那一行。现在来查看下:

[rocrocket@localhost ~]$ cat /etc/passwd|grep ^rocrocket
rocrocket:x:500:500:rocrocket,China:/rocrocket/PSB/home:/bin/zsh

你可以发现输出内容的最后部分已经变成了/bin/zsh了,下次重启的时候,linux就会读取这一命令来启动shell了!

把shell修改回/bin/bash:

[rocrocket@localhost ~]$ chsh -s /bin/bash
Changing shell for rocrocket.
Password:
Shell changed.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.