When connecting via SSH, many developers find themselves stuck with Bash despite preferring alternative shells like ZSH. The frustration doubles when your carefully crafted .zsh_profile or .zshrc doesn't load automatically during remote sessions.
Your login shell is determined by multiple layers:
- System default (usually Bash in most Linux distros)
- User configuration in
/etc/passwd - SSH forced command (if configured by admin)
The most reliable method is changing your default shell system-wide:
# Check available shells
cat /etc/shells
# Change your default shell to ZSH
chsh -s $(which zsh)
This modifies your entry in /etc/passwd to point to ZSH. Note that you'll need to log out and back in for changes to take effect.
If you can't change system defaults, add this to your local ~/.ssh/config:
Host myserver
HostName server.example.com
User yourusername
RequestTTY yes
RemoteCommand exec zsh -l
To ensure your ZSH profile loads correctly during SSH sessions, verify these files exist and are readable:
~/.zprofile # Login shell initialization
~/.zshrc # Interactive shell configuration
Test with this command to confirm proper loading:
ssh user@host 'echo $SHELL && echo $0 && zsh -ic "echo ZSH loaded successfully"'
When you SSH into a Linux/Unix system, your login shell is determined by the /etc/passwd file entry for your user. The last field in each line specifies the default shell:
username:x:1000:1000:User Name:/home/username:/bin/bash
The most reliable way to ensure ZSH loads with your profile is to change your default shell system-wide:
# Check available shells
cat /etc/shells
# Change shell for current user
chsh -s $(which zsh)
After running this command, all new SSH sessions will automatically use ZSH.
If you can't change system defaults, you can force a shell via SSH configuration:
# ~/.ssh/config
Host myserver
HostName server.example.com
User myusername
RequestTTY yes
RemoteCommand zsh -l
To make sure your .zsh_profile loads properly, verify these files exist in your home directory:
~/.zshrc
~/.zprofile
~/.zshenv
The loading order is important: .zshenv → .zprofile → .zshrc.
If your shell changes but profiles don't load:
# Check if shell is interactive
[[ $- == *i* ]] && echo "Interactive" || echo "Not interactive"
# Force interactive mode
ssh user@host -t "zsh -i"
For system administrators wanting to set ZSH as default for all users:
# Install ZSH if needed
sudo apt install zsh # Debian/Ubuntu
sudo yum install zsh # RHEL/CentOS
# Set as default shell
sudo usermod -s /bin/zsh username