AIX - how to change user shell to bash?

17,310

Solution 1

You normally would run chsh (see for example Changing Shells on IBM AIX). However, if bash is not listed in these files, then you could break your login:

  • /etc/shells and
  • /etc/security/login.defs

As a workaround, you could make your shell's login initialization script run bash directly. That would work if your shell is csh, for instance, by modifying .login.

If your login shell is ksh, that is a little harder: AIX's ksh uses .profile (which is used by other shells), and does not set special variables. Something like this might work for you, in .profile:

[ $SHLVL = 1 ] && exec bash

Both ksh and bash set this variable; it should be 1 as you just log in, and incremented when you transfer to bash.

When experimenting with things like this, it is important to have a workable shell on the remote machine, and test logins using a different connection, in case there is a problem with your edits.

Solution 2

Thomas reminded me of this. I use several AIX servers and not all servers have bash. I do prefer bash though. I put this in my .profile.

case $- in
  *i*)
    # Interactive session. Try switching to bash.
    if [ -z "$BASH" ]; then # do nothing if running under bash already
      bash=$(command -v bash)
      if [ -x "$bash" ]; then
        export SHELL="$bash"
        exec "$bash"
      fi
    fi
esac
Share:
17,310

Related videos on Youtube

Mercer
Author by

Mercer

Updated on September 18, 2022

Comments

  • Mercer
    Mercer over 1 year

    I want to know how I can run bash automatically when I log into my AIX server. How can I do that without having to type bash every time I log into my AIX server?