This post will guide you how to run local bash aliases over ssh session to remote server in Linux system. How do I load local shell aliases to ssh session in SSH Client.
Run Local Bash Aliases over SSH Session
When you log in to a remote machine using ssh, and you wish to run local bash aliases and functions. if you passed it to ssh command directly, it will prompt “bash: ll: command not found” error message.
[myuser@osetc~]# ssh -t osetc.com 'll' myuser@osetc.com's password: bash: ll: command not found
So How to load the local bash aliases over ssh session. you can use the -t and -ic options, just like below command:
ssh -t username@hostname /bin/bash -ic 'aliases command'
Note:
The -i option tells bash to run an interactive shell. Aliases are enabled by default only in interactive shells.
The -t options tells ssh to allocate a pseudo-tty. Without this, bash emits a warning message when started in interactive mode. This also enables ls colors. Without it, you’d have to use –color=always, see man ls.
Let’s see the following example:
# ssh -t myuser@osetc.com /bin/bash -ic 'll'
Outputs:
[root@osetc.com ~]# ssh -t @myuserosetc.com /bin/bash -ic 'll ' myuser@osetc.com's password: total 85672 -rw-------. 1 root root 1628 Nov 29 14:50 anaconda-ks.cfg -rw-------. 1 root root 580 Nov 29 14:50 original-ks.cfg Connection to osetc.com closed.