chsh:“您不能更改‘用戶名’的 shell。”

chsh:“您不能更改‘用戶名’的 shell。”

我正在嘗試更改我的用戶的預設外殼程式。但我不斷收到此錯誤:

$ chsh
You may not change the shell for 'flimm'.
$ chsh -s "$(which bash)"
You may not change the shell for 'flimm'.

我試圖理解為什麼我不能為我的用戶更改外殼。

答案1

由於您確認這/usr/bin/chsh是 setuid root(因此應該允許非特權使用者更改自己的登入 shell),對此行為最可能的解釋是

  • 您目前的登入 shell 不在 /etc/shells 檔案中

或者

  • 您目前的登入 shell 受到限制(很可能/bin/rbash

前任。

$ grep fish /etc/shells || echo "invalid shell"
invalid shell
$ 
$ sudo chsh -s /usr/bin/fish testuser
$ 
$ su - testuser
Password:
Welcome to fish, the friendly interactive shell
testuser@t400s ~> chsh -s /bin/bash
You may not change the shell for 'testuser'.
testuser@t400s ~> exit

請注意,對於 root 將使用者的登入 shell 設定為無效 shell 沒有任何限制(如此處),並且這樣做不會透過將其新增至 /etc/shells 檔案來使無效 shell 變得有效。

$ sudo chsh -s /bin/rbash testuser
$     
$ su - testuser
Password:
testuser@t400s:~$
testuser@t400s:~$ chsh
You may not change the shell for 'testuser'.
testuser@t400s:~$ exit

如果目標/etc/shells 檔案中缺少 shell,您會收到不同的訊息:

$ sudo chsh -s /bin/bash testuser
$ 
$ su - testuser
Password:
testuser@t400s:~$ chsh -s /usr/bin/fish
Password:
chsh: /usr/bin/fish is an invalid shell

答案2

您可以嘗試使用指令 sudo usermod -s /bin/bash flimm

答案3

使用者的登入 shell 保存在 中/etc/passwd,並且不會被普通使用者修改。您可以使用 來查看它getent passwd $USER
如果您的新 shell 已在 中列出/etc/shells,您可以使用以下命令進行變更:

sudo chsh -s $(type -p bash) $USER

與登入資訊的所有操作一樣,請確保在另一個終端機 ( Ctrl-Alt-F3) 上有登入工作階段,以防您破壞某些內容而無法登入。

相關內容