5

I work as a sysadmin in a large company and have to maintain several windows and Linux (Ubuntu 16.04) VMs. Since I want to use zsh instead of bash on the Linux VMs, I have to change my default shell.

Now, I log in on Linux with my Windows domain account which enforces the AD settings; that means I can't change the passwd file or use chsh to change my default shell, so I had to find another way. This way was to enforce the shell in AD with the loginShell attribute.

The question is, what happens if I log in on a Linux VM which does not have zsh installed, what happens? Does it fallback to bash/sh, does it get stuck or something else?

6

Let's try!

Shell changed on the server:

[myserver ~]% getent passwd myuser
myuser:x:150:150:myuser:/home/myuser:/foo

Let's log in:

[myclient ~]% ssh myserver
Received disconnect from myserver: 2: Too many authentication failures for myuser

From the SSH logs on the server:

Nov 22 09:30:27 myserver sshd[20719]: Accepted gssapi-with-mic for myuser from myclient port 33808 ssh2
Nov 22 09:30:27 myserver sshd[20719]: pam_unix(sshd:session): session opened for user myuser by (uid=0)
Nov 22 09:31:18 myserver sshd[20727]: Received disconnect from myclient: 11: disconnected by user
Nov 22 09:31:18 myserver sshd[20719]: pam_unix(sshd:session): session closed for user myuser
Nov 22 09:31:20 myserver sshd[20828]: User myuser not allowed because shell /foo does not exist
Nov 22 09:31:20 myserver sshd[20835]: input_userauth_request: invalid user myuser
Nov 22 09:31:20 myserver sshd[20835]: Disconnecting: Too many authentication failures for myuser

Key line: User myuser not allowed because shell /foo does not exist. So you can't log in if you don't have a valid shell set.

3

There is no fallback. There would be an error message such as...

Cannot execute /does/not/exist: No such file or directory.

You could add the invocation of zsh without modifying AD.

echo 'exec zsh' >> ~/.bashrc

Then, every time you log in with bash, you start zsh automatically.

2
  • 1
    I think you ment to write exec zsh instead of echo zsh. (I would have edited it myself, but UL insist that I need to change at least 6 characters. Next time, please make a more significant mistake to correct ;-) )
    – Adaephon
    Nov 23 '16 at 8:51
  • @Adaephon Yes, that is a better invocation of zsh to match the ops purpose, thank you. Future readers: the exec call replaces the current login shell specified in /etc/passwd (or from AD or another directory) with the shell specified in ~/.bashrc. No stray processes, no need to log out of each shell. Nov 23 '16 at 14:20
0

As stated, you will be stuck in a login loop, and incapable of login in.

Unfortunately, the current answer will also cause login loops if used, as the exec call will crash. It will also ignore the arguments given to bash, preventing most complex use cases.

Adding

[ -x "$(command -v zsh)" ] && exec zsh "$@"

as the fist line of .bashrc will first check if zsh is available

Adding

[ -n "$GNOME_TERMINAL_SCREEN" ] && [ -x "$(command -v zsh)" ] && exec zsh "$@"

should also check if you are running the shell in the gnome terminal instead of a tty

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.