How to change default shell when login


#1

Hi,

Is there way to change default shell when I login VyOS? Now the default shell is /bin/vbash, but I want to use /bin/sh. I used ‘chsh’ to change, but it doesn’t work, after rebooting, the default shell will be changed back to /bin/vbash. Any idea to archive that?

best regards.


#2

Yes, it’s reset on purpose, otherwise you may break your cli functionality in many places. However you can enforce that via setting the immutable flag for /etc/passwd, that way it /etc/passwd can’t be rewritten but you also can’t create any user etc. So, use that on your own risk.


#3

thanks for reply, after making immutable for /etc/passwd, the default shell in /etc/passwd will not change after rebooting, but it means nothing since the default shell still be vbash after login, is there settings in VyOS to overwrite shell settings anyway?


#4

Is there any particular reason you need the default shell to be /bin/sh ? Outside of vbash you will lose most of the VyOS CLI functionality. If you need it for script running you can always change the shell at the start of the session as shown below.

vyos@vyos:~$ whoami
vyos
vyos@vyos:~$ echo $0
-vbash
vyos@vyos:~$ /bin/sh
sh-4.3$ echo $0
/bin/sh
sh-4.3$ whoami
vyos
sh-4.3$

#5

works for me in the latest rolling:

vyos@vyos:~$ cat /etc/passwd| grep vyos && echo $0
vyos:x:1003:100::/home/vyos:/bin/bash
-bash

@joshua the environment variables will stay with bash as well, however there is some additional functionality in vbash, bash would have. (https://github.com/vyos/vyatta-bash/commit/45b687cc08e0a67747d09013ce0ad5e5d04abb1f just an example, I would have to dive into it to find more relevant code lines). In general, yes, the method you have propose is the recommended one, thanks for pointing that out.