Is there any way to run chsh -s /bin/zsh without being root and without being asked for the password? I want to put it into a non-interactive script that isn't called by root.

  • 1
    I'm not prompted for a password when I do that, it just changes my shell and exits Aug 4, 2011 at 18:20
  • 1
    @Michael What distro are you using? I'm in Ubuntu 11.04. Aug 4, 2011 at 18:52
  • Gentoo. sys-apps/shadow- Aug 4, 2011 at 19:13
  • 2
    Why do you need to do this? Can you get root to cooperate (e.g. by adding a custom sudoers rule)? It's rare to need to automate something over multiple accounts without being root. Aug 4, 2011 at 19:40

3 Answers 3


If you don't have the permission to change your login shell, you can tell bash (I assume bash is your login shell) to replace itself with zsh. In your ~/.bash_login, add this line:

exec /bin/zsh --login
  • 3
    Whoa, careful! With some distributions or desktop environments (I don't remember specific cases outright), if you do this, you'll find that you can't log in under X (because /etc/?dm/Xsession calls bash --login). Aug 4, 2011 at 19:39
  • Gilles, what would you suggest instead? Aug 4, 2011 at 19:51
  • 1
  • This seems to break all non interactive commands(scp, rsync).
    – Wei Qiu
    Oct 12, 2018 at 9:29

If your version of chsh requires a password (mine does), you will need to setup sudo with special permissions. You can configure it to allow access to any program without prompting for a password like this:

user   ALL=(ALL) NOPASSWD:/usr/bin/chsh

Where "user" is your username (or prefix with % for a group name). Make sure specify the full path to your chsh. This will not allow the user to run anything ELSE as root (including from a script) but it will allow that one binary to be run as root without a password, thus bypassing the user-password prompt.


Depending on your exact needs, if you want to do this because you’re running a long script and don’t want it to hang in the middle to that question, you can ask for the password upfront and then execute chsh with sudo privileges, reading the password from stdin.

read -p 'What is your password?' sudo_password

# rest of the script here

sudo -S chsh -s '/bin/zsh' "${USER}" <<< "${sudo_password}"

-S causes sudo to read the password from stdin. Be aware of possible security risks with this approach (I haven’t been able to reproduce that, though, and again, depending on your needs this might not be an issue).

You must log in to answer this question.

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