Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
1  
I'm not prompted for a password when I do that, it just changes my shell and exits –  Michael Mrozek Aug 4 '11 at 18:20
1  
@Michael What distro are you using? I'm in Ubuntu 11.04. –  Matt Alexander Aug 4 '11 at 18:52
    
Gentoo. sys-apps/shadow-4.1.4.3 –  Michael Mrozek Aug 4 '11 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. –  Gilles Aug 4 '11 at 19:40

2 Answers 2

up vote 1 down vote accepted

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
share|improve this answer
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). –  Gilles Aug 4 '11 at 19:39
    
Gilles, what would you suggest instead? –  Matt Alexander Aug 4 '11 at 19:51
    

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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