How to use/run bash aliases over ssh based session

Bash aliases are only available in the current shell session, so they are not automatically available in an SSH-based session. However, you can make your aliases available in an SSH-based session by adding them to a shell startup file, such as ~/.bashrc, ~/.bash_profile, or ~/.bash_aliases.

Here’s an example of how you could create an alias for the ls command in ~/.bashrc:

 
$ echo "alias l='ls -lh'" >> ~/.bashrc

This will create an alias l for the ls -lh command in your ~/.bashrc file. You can then source the file to make the alias available in your current shell session:

 
$ source ~/.bashrc

Now, you can use the alias l just like any other command in your shell session. When you log in to a remote system using SSH, your ~/.bashrc file will be automatically sourced, and your aliases will be available in the SSH-based session as well.

Note that different systems may have different startup files, so you may need to modify the appropriate file for your system. You can also create a new file, such as ~/.bash_aliases, specifically for your aliases, and source it from your shell startup file.

Leave a Comment