To use bash aliases over an ssh-based session, you will need to have the aliases defined in the ~/.bashrc
file of the user account on the remote system. The ~/.bashrc
file is executed whenever a new terminal session is started, and any aliases defined in this file will be available to the user in the terminal.
To define a new alias in ~/.bashrc
, you can use the alias
command. For example, to create an alias for the ls
command that lists files in long format with a colored output, you can add the following line to ~/.bashrc
:
alias ls='ls -l --color'
To make the new alias available in the current terminal session, you will need to source the ~/.bashrc
file by running the following command:
source ~/.bashrc
After sourcing ~/.bashrc
, you will be able to use the ls
alias by typing ls
at the command prompt.
If you are using an ssh-based session to connect to the remote system, you will need to make sure that the ~/.bashrc
file is executed whenever you start a new terminal session. You can do this by adding the following line to the end of the ~/.bash_profile
file on the remote system:
if [ -f ~/.bashrc ]; then source ~/.bashrc fi
This will cause the ~/.bashrc
file to be sourced whenever a new terminal session is started, including when you connect to the remote system via ssh.
It is also possible to define aliases on the command line when connecting to the remote system using ssh. To do this, you can use the -t
option to specify a command to be run after the ssh connection is established. For example:
ssh user@remote -t 'alias ls="ls -l --color"; exec bash'
This will create the ls
alias and start a new bash shell on the remote system. The exec bash
command will replace the current ssh process with a new bash shell, allowing you to use the ls
alias in the terminal.