当您在没有用户名的情况下 chsh 时会发生什么?

Atu*_*ams 3 chsh

人们可以: sudo chsh -s /bin/sh 或者 sudo chsh -s /bin/sh user_name

据了解,第二个命令更改了指定用户名的 shell,但不清楚在不指定用户名的情况下会发生什么以及反映在哪里?

谢谢你!

Ter*_*nce 6

没有用户的命令更改 root 用户:

terrance@terrance-ubuntu:~$ sudo chsh -s /bin/sh
terrance@terrance-ubuntu:~$ cat /etc/passwd | grep "/bin/sh"
root:x:0:0:root:/root:/bin/sh
terrance@terrance-ubuntu:~$ sudo chsh -s /bin/bash
terrance@terrance-ubuntu:~$ cat /etc/passwd | grep "/bin/bash"
root:x:0:0:root:/root:/bin/bash
Run Code Online (Sandbox Code Playgroud)

  • sudo chsh 更改 root 的 shell 的原因是 sudo 切换到 root,而 chsh 更改当前用户的 shell。 (8认同)
  • 具体来说,使用“sudo”是一个坏主意:普通用户仅限于“/etc/shells”中列出的 shell,因此用户不会通过切换到非工作 shell 来意外地将自己锁定。作为 root,您可以设置任何内容,包括不起作用的内容。 (3认同)
  • @AturSams 正确,与此相同。要在您自己的用户上运行该命令,不需要 sudo,也不需要您的用户名。 (2认同)