Skip to content
Log In Sign Up info@muvcloud.com

Where .bashrc Lives

Each user has their own file, in the home folder:

ls -a ~
nano ~/.bashrc

The dot at the start of the name hides the file from a plain ls; -a shows it. For the user deploy the full path is /home/deploy/.bashrc, and for root it is /root/.bashrc. Settings for every user go in /etc/bash.bashrc on Debian and Ubuntu and in /etc/bashrc on AlmaLinux and Rocky Linux.

Back It Up and Keep a Second Session Open

Before you edit the file on a server:

  1. Copy it: cp ~/.bashrc ~/.bashrc.bak.
  2. Keep your current SSH session open while you work.
  3. After saving, check the syntax with bash -n ~/.bashrc. No output means no syntax errors.
  4. Open a second SSH session and confirm that it logs in normally before you close the first.

Add Aliases

An alias is a short name for a longer command. Add lines like these at the end of the file:

alias ll='ls -lah'
alias ..='cd ..'
alias logs='sudo journalctl -f'
alias ngt='sudo nginx -t'

Type alias to list the active ones, and unalias ll to remove one from the current shell. Avoid aliases that change what a standard command such as rm does: on another server, or for a colleague, the command will behave differently.

Add a Folder to PATH

PATH is the list of folders the shell searches for commands. To add your own scripts folder, put it in front of the current value:

export PATH="$HOME/bin:$PATH"

Always keep $PATH in the line. Writing export PATH="$HOME/bin" alone drops every system folder, and commands such as ls stop being found in that shell. Check the result with echo "$PATH".

Change the Prompt with PS1

The PS1 variable sets the prompt. Special sequences fill in values: \u is the user, \h the host name, \w the current folder, and \$ shows # for root and $ for other users.

PS1='[\u on \h \w]\$ '

A prompt with the host name tells you which server a terminal belongs to before you run a command there. Other everyday commands worth an alias are in the Linux commands cheat sheet.

Reload with source

Changes apply only to new shells. To load them into the shell you are in:

source ~/.bashrc

. ~/.bashrc is the short form of the same command. Reloading adds new settings but does not undo removed ones: an alias you deleted from the file stays until you log out or run unalias.

.bashrc vs .bash_profile and .profile

A login shell, such as the one an SSH login starts, reads the first of ~/.bash_profile, ~/.bash_login, and ~/.profile that it finds; an interactive non-login shell reads only ~/.bashrc. The default ~/.profile on Debian and Ubuntu and the default ~/.bash_profile on AlmaLinux and Rocky Linux load ~/.bashrc themselves, so one file covers both cases. Put aliases and the prompt in .bashrc. The full picture is in types of shells in Linux.

When a Broken .bashrc Locks You Out

Debian, Ubuntu, AlmaLinux, and Rocky Linux build Bash with an option that makes it read ~/.bashrc also when the SSH server runs a command without a terminal, as scp, sftp, rsync, and ssh user@your_server_ip uptime do. Anything in the file that prints text or fails can then break file transfers, even though an interactive login looks fine. The default file on Debian and Ubuntu begins with a case $- block that returns at once when the shell is not interactive; keep it at the top and add your lines below it. Where a file has no such block, as on AlmaLinux and Rocky Linux, wrap commands that print text in a test such as [[ $- == *i* ]].

If logins break:

  1. In the session you kept open, restore the copy with cp ~/.bashrc.bak ~/.bashrc, or fix the line.
  2. Without an open session, log in through the console in your provider's control panel as root or another user and repair the file there.
  3. To return to the distribution's default, copy it from /etc/skel, the folder new home folders are created from: cp /etc/skel/.bashrc ~/. As root for another user, copy it to that user's home and then run chown deploy:deploy /home/deploy/.bashrc.

If you edit the file in Vim, see how to save and quit in Vim.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations