用 chsh 更换默认登录 Shell
把 fish、zsh 设为每次登录自动启动的默认 Shell,一条命令永久生效。
运行 chsh -s /usr/bin/fish 并输入密码,注销后重新登录即可使用新 Shell。
01命令
命令
$ chsh -s /usr/bin/fish02作用说明
chsh 修改的是 /etc/passwd 里你的 Shell 字段,登录管理器和 SSH 读取的正是这里——这和在 .bashrc 里改 SHELL 变量不同,后者只影响当前会话。新 Shell 必须登记在 /etc/shells 中,chsh 才会接受,而且要写绝对路径不能只写名字。用 echo $SHELL 查看当前 Shell,用 cat /etc/shells 查看可用选项。
03风险
!注意: 路径写错可能导致无法登录——先用 which fish 确认路径,切换后测试期间保留一个已打开的 root 会话以防万一。
04撤销
撤销
$ chsh -s /bin/bash05来源
- chsh(1) — change your login shell依据: Man page documents chsh changing the login shell and the -s/--shell option; confirms 'chsh', 'shell' and 'login' appear in the text.
- chsh(1) — Ubuntu man page依据: Man page text includes -s, --shell (specify login shell) and the note that the new shell must be listed in /etc/shells.
最后验证: 2026-09-19 · 分类: 系统与设置