How do I set the shell in Solaris/SunOS for my user only, without access to /etc/passwd or any other su stuff?

It should thereafter work both for interactive ssh (1) and ssh when you send commands (2).

uname -a says SunOS ... 5.10 Generic_148889-04 i86pc i386 i86pc

Edit in response to comments and answers

There is no chsh.

I can't do /usr/bin/passwd -e - permission denied.

The default shell is bash. I would like zsh.

I already tried to set the SHELL environment variable manually, and start the shell manually in the .profile file, only this doesn't work for my second case (2): ssh user@host command will run command in bash.

As compared to getting my preferred shell when I login, it is minor, so the workaround is certainly worth mentioning, only, my intention with this question was to get it right the right way. Because it just relates to one user, I thought it was doable without involving the SA, but now I'm less certain. (But any workaround that solves (1) and (2) is cool, for sure.)

  • Can you state what your current login shell is and what shell you want to set instead ? – jlliagre Jun 28 '13 at 5:27
  • To anyone reading @jlliagre above, check out his answer and the comments below it. – Emanuel Berg Jun 28 '13 at 20:33
  • @jlliagre: No, I get an error message saying bash cannot find my zsh noglob. – Emanuel Berg Jun 30 '13 at 21:14
  • @jlliagre: Without the solution below, bash says there is no such command (which makes sense), so of course the problem is that bash runs the command, and the solution is to have zsh run the command, and then it works. Try noglob echo * - bash will fail on noglob but zsh will echo *. – Emanuel Berg Jul 1 '13 at 16:52
  • @jlliagre: command, for example, is noglob echo *. – Emanuel Berg Jul 1 '13 at 21:08

The SHELL=newshell; exec "$SHELL" trick has already been covered.

Now, if you also want commands run over ssh to use your new shell. If the current login shell is bash, you can add this to your ~/.bashrc:

if [ -n "$BASH_EXECUTION_STRING" ]; then
  export SHELL=/bin/zsh

That will execute something with the new shell whenever bash is started with bash -c something and it reads ~/.bashrc.

Shells started with bash -c something generally do not read the ~/.bashrc. An exception is when those bash are called by sshd or rshd, or upon bash -ic something.

You could add a check for [ -n "$SSH_CONNECTION" ] if you only want to cover the ssh case.

  • Yes, the $BASH_EXECUTION_STRING chunk in .bashrc and the "trick" in .profile work. – Emanuel Berg Jun 28 '13 at 21:47
  • 1
    Why not make the test [[ $- != *i* ]], i.e. this bash instance isn't interactive? – Gilles 'SO- stop being evil' Jun 28 '13 at 22:10
  • @Gilles: Care to explain how that would be an improvement? – Emanuel Berg Jun 30 '13 at 21:25
  • @EmanuelBerg Why would you want an explicit call bash -ic 'somecommand' to run zsh -ic 'somecommand' instead? – Gilles 'SO- stop being evil' Jun 30 '13 at 21:30
  • @Gilles: Are you saying it should be like above, only the condition changed into what you propose? – Emanuel Berg Jun 30 '13 at 21:38

method #1: with chsh

Usually you can use the command chsh to change your shell without having to have access to the /etc/passwd. This is the file that typically lists your default shell, for example:

saml:x:500:501:Sam M. (local):/home/saml:/bin/zsh

A normal user may only change the login shell for his/her own account, the super user i.e. root user may change the login shell for any account. You can see what shells are available on your system with this command:

$ chsh --list-shells

To change your shell you can use this command:

$ chsh -s /bin/zsh saml
Changing shell for saml.
Shell changed.

The effect is obvious if you look in the /etc/passwd file:

$ grep saml /etc/passwd
saml:x:500:501:Sam M. (local):/home/saml:/bin/zsh

You won't see the change immediately. You'll have to logout/login to see it:

[saml@grinchy]~% echo $SHELL

method #2: /usr/bin/passwd -e

If you don't have access to the command chsh which apparently you don't on Solaris, and you don't have root access to change it in /etc/passwd, you might be able to still do the same with this command:

$ /usr/bin/passwd -e

method #3: manually set it method

If neither of the above methods are an option you're basically left with this last option, which is to add one of following to your existing shell's login files:

  1. default shell: /bin/csh or /bin/tcsh

    Add the following lines to $HOME/.login:

    setenv SHELL=/bin/bash
    exec $SHELL
  2. default shell: /bin/bash

    Add the following to $HOME/.bash_profile:

    export SHELL=/bin/zsh
    exec $SHELL

Some additional things to consider with the above, you can make them more bullet proof by performing a check to see if the current $SHELL already is /bin/bash for example, prior to setting it. If it is, do nothing, otherwise go ahead and perform the exec $SHELL.


  • Unfortunately, Solaris doesn't provide chsh, so unless the local admin installed it, that won't help here. – alanc Jun 28 '13 at 3:17
  • @alanc - what about /usr/bin/passwd -e? – slm Jun 28 '13 at 3:39
  • passwd -e won't work either, unless the user account is centrally stored (NIS, LDAP, ...) which isn't the case here. – jlliagre Jun 28 '13 at 3:58
  • @jlliagre: So certain are you? I use passwd -e to change my shell on my Solaris systems which use neither NIS nor LDAP. – bahamat Jun 28 '13 at 5:21
  • I guess the exec in .profile won't lead to an endless loop because Bash doesn't read this file when invoked this way ...? – tripleee Jun 28 '13 at 5:23

You can't do it with a vanilla Solaris installation. A simple workaround would be to modify your profile to exec the wanted shell.

Eg, assuming /etc/passwd states your shell is /bin/bash but you prefer /bin/ksh:

$ tail -2 ~/.bash_profile
export SHELL=/bin/ksh
exec $SHELL

Beware not to lock you out with a typo or not to enter an infinite loop with bogus exec or logic.

  • Setting $SHELL would also make sure that commands that start a shell (like xterm, vi...) also start your new prefered shell. – Stéphane Chazelas Jun 28 '13 at 7:38
  • @StephaneChazelas Indeed, answer updated. – jlliagre Jun 28 '13 at 9:10
  • I did this already, including what @StephaneChazelas suggested, only, for ssh user@host command it still tries to use bash, so it won't work for noglob and such zsh stuff. A workaround to that - include the shell in the command? – Emanuel Berg Jun 28 '13 at 20:32
  • Can you please clearly state what is the shell set for your account and the shell you want it to be replaced with ? – jlliagre Jun 28 '13 at 20:38
  • @jlliagre: I made an edit to the question. – Emanuel Berg Jun 28 '13 at 20:46

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.