3

One may: sudo chsh -s /bin/sh or sudo chsh -s /bin/sh user_name

It is understood that the second command changes the shell for the specified user_name but unclear what happens without specifying a user_name and where is that reflected?

Thank you!

AturSams
  • 213
  • 1
  • 12

1 Answers1

6

The command without a user changes the root user:

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
Terrance
  • 39,774
  • 7
  • 116
  • 176
  • 1
    So it is essentially like typing `sudo chsh -s /bin/bash root` ? – AturSams Jan 17 '23 at 08:12
  • 2
    @AturSams Correct, it is the same as that. To run the command on your own user, sudo is not needed and neither is your username. – Terrance Jan 17 '23 at 13:00
  • 3
    Specifically, using `sudo` is a bad idea: normal users are limited to shells listed in `/etc/shells`, so users cannot accidentally lock themselves out by switching to something that isn't a working shell. As root, you can set anything, including something that doesn't work. – Simon Richter Jan 17 '23 at 13:36
  • 8
    The reason `sudo chsh` changes the shell for root is that `sudo` switches to root, and `chsh` changes the shell of the current user. – Simon Richter Jan 17 '23 at 13:37
  • @SimonRichter Thanks for clarifying. :) – AturSams Jan 17 '23 at 15:42
  • Which makes quite a bit of sense; `chsh` without `sudo` would change the user's own shell. I'm kind of disappointed that on too many linux systems, `chsh` without `sudo` yields an error. – Joshua Jan 17 '23 at 19:32