GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — linux-command/command/chsh.md at master · javamickey/linux-command

Expand file tree

/

chsh.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
93 lines (65 loc) · 2.04 KB
/

chsh.md

Copy path

File metadata and controls

93 lines (65 loc) · 2.04 KB
Raw
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.