I use a samba4 domain account to log in on my laptop. I wanted to try zsh out, but since my user doesn't reside in /etc/passwd I found that chsh can't find my user. Can anyone advise how I can change my login_shell?

I couldn't see anything in my ldap.conf, nssswitch.conf or anything in /etc/pam.d that helped...

Looking on the domain controller I thought maybe I could use samba-tool, but I saw nothing in help that pointed me in the right direction...

5 Answers 5


I asked about this in the #suse channel on Freenode, and Miuku suggested the same as Arul, however, he mentioned two things, if I were using a Windows domain I could set the loginShell attribute.

Sadly, I'm on a samba domain, so that didn't help. But his final suggestion was perfect, get the output of:

getent passwd USERNAME

This will have the valid entry equivalent for your user in /etc/passwd, take this, paste it in to /etc/passwd and update the shell at the end for the valid path of the shell you want to use. This way it doesn't change it for all users, and you can make sure that shell is on the machine you're configuring this on before making the change.

  • 1
    If you don't want to copy and paste, you can use: getent passwd `id -un` | sudo tee -a /etc/passwd. Not sure if it works in all shells but at least bash and tcsh are ok. Feb 21, 2018 at 4:07
  • Doing this on a RHEL 7 box connected to a Windows AD domain caused me to be locked out of the server until the line was removed from the /etc/passwd file...
    – Taegost
    Dec 20, 2018 at 21:38
  • Thanks for the info @Taegost, I hadn't tried on RHEL
    – Rumbles
    Dec 24, 2018 at 11:52
  • 1
    This works if you change the * to x. * is interpreted as an account lockout, so you'll never be able to login. x allows authentication. See this stackexchange link for more info. Mar 5, 2021 at 15:58
  • I needed * on my system (Ubuntu 20.04) and x didn't work. From man passwd: > If the password field is a lower-case “x”, then the encrypted password is actually stored in the shadow(5) file instead; there must be a corresponding line in the /etc/shadow file, or else the user account is invalid. > If the password field contains some string that is not a valid result of crypt(3), for instance ! or *, the user will not be able to use a unix password to log in (but the user may log in the system by other means)
    – iliis
    Jul 8, 2022 at 10:02

I had exactly the same issue. Since not all machines in my domain have zsh installed, and since I did not want to affect all users, I ended up putting in my .bashrc:

if [ -x /usr/bin/zsh ]; then
  echo 'starting zsh'
  # export SHELL=/bin/zsh #edit: this is probably not what you want, see the comment.
  exec /usr/bin/zsh

This might be inelegant, but at least it gets the job done.

  • Someone at my work was doing something similar recently, he had issues with his method not loading the .zshrc file. I don't know if your method would work in that respect, have you tried it? Also, your SHELL variable isn't the same as the path to your zsh bin, is that correct? I changed their config to my method of setting it in the passwd file
    – Rumbles
    Feb 15, 2018 at 10:18
  • Interesting - my .zshrc is correctly read. about your second point, thanks for brining it up, it was a mistake from my side. See here for an answer: unix.stackexchange.com/questions/330233/… Feb 15, 2018 at 13:07
  • Well it's definately one way of doing it, I still prefer to set it in the /etc/passwd file as with my accepted answer as you don't invoke bash then load zsh with bash (plus I guess if you press ctrl-D in your setup you are dropped to a bash shell?) - It does require the user to ensure you have zsh installed and for an admin to make the change
    – Rumbles
    Feb 15, 2018 at 13:21
  • Wouldn't it be better, instead of using /usr/bin/zsh, to instead use exec /usr/bin/zsh to replace the bash shell process with the zsh shell process? Aug 27, 2018 at 21:06
  • I think you may be right @TrippKinetics. Aug 31, 2018 at 10:53

If you have access to edit the samba domain controller config, you can set the following property that allows you to set the shell in smb.conf

template shell    = /bin/zsh

Not sure what happens if you login to a machine that does not have zsh installed (not all distros have zsh installed by default), but my guess is that it will invoke distro default shell.

If you simply want to try it, just type zsh to get a subshell which I am sure you know that already.

  • Thanks, but won't that affect all users, not just mine?
    – Rumbles
    Nov 15, 2015 at 14:14
  • Yes, it is a global parameter that affects all users. In this case, all users who have zsh installed. I am not sure you can restrict this to specific user but I would check idmap uid parameter which might allow you to do that. Nov 15, 2015 at 14:56
  • Thanks, but that's not what I'm after. I don't want to change everyone shell, I just want to change my shell. I tried changing this setting in my local smb.conf and after rebooting it had no effect
    – Rumbles
    Nov 16, 2015 at 9:47

However this answer is correct, additionally, for a concise one-line solution, you may use the following command:

sudo sh -c "getent passwd $USER | sed 's:/bin/bash:/bin/zsh:' >> /etc/passwd"
  • getent passwd $USER: Fetches the entry for the user specified in the $USER variable.
  • sed 's:/bin/bash:/bin/zsh:': This part uses sed, the stream editor, to replace /bin/bash with /bin/zsh in the output of getent. This assumes that the default shell is /bin/bash; if it's different, you'll need to adjust this part accordingly.
  • >> /etc/passwd: Appends the modified output to the end of the /etc/passwd file.

This is a subjective solution which could be useful for some.

Since I use MobaXterm, my method was to just configure my session settings and tell it to use bash. Right-Click on your specific Session > Edit Session then type bash in the Execute command input box.

Since my account is also a domain account, I did not have an entry into /etc/passwd and I also did not want to modify any environment settings that could break my shell. This method is simple and non-destructive. You can then create your ~/.bashrc file and configure your shell the way you want.

bash configuration in MobaXterm

  • This would be how you update the shell that your terminal application runs for you when you open it, but it isn't the default shell for the account
    – Rumbles
    Aug 1, 2023 at 13:02
  • @Rumbles - Did you downvote this answer? Well, like I said, it may help some people. Probably not you. I landed on this question here because I had the same. I searched and searched but the solution that worked well for me was this workaround posted here, especially if one doesn't have sudo rights to edit anything.
    – Shailen
    Sep 15, 2023 at 15:25
  • I have because you've not answered my question, this does not update the default shell on the account, instead it updates the shell used by this application. If you get a TTY and log in, you're still going to get the shell configured by the os, not this application
    – Rumbles
    Sep 17, 2023 at 7:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .