×


How to use and run bash aliases over ssh based session

Are you facing issues with executing bash shell aliases when using ssh command?

This guide will help you.

An SSH client is a software program which uses the secure shell protocol to connect to a remote computer.
Here at LinuxAPT, we regularly help our Customers to fix Linux related errors as part of our Server Management Services.
In this context, we shall look into the process to execute commands and bash shell aliases on a remote machine using the ssh command.

More information about SSH client (ssh)?

SSH client (ssh) is basically a Linux command for logging into a remote server and for executing shell commands on a remote system. It is designed to provide secure encrypted communications between two untrusted machines over an insecure network such as the Internet.


How to run or execute commands with Linux ssh client?

Lets say, you want to run a command such as "date" command using an ssh tool such as putty, you do so by running;

$ ssh root@server1.linuxapt.com date

More information about bash shell and command types?

The following types of commands are used in bash shell;
i. Aliases such as ll
ii. Keywords such as if
iii. Functions (user defined functions)
iv. Built in such as pwd
v. Files such as /bin/date


You can use "type command" or "command command" to find out a command type as shown below;

$ type -a date
$ type -a free
$ command -V pwd
$ type -a file_repl

How to run bash aliases using ssh client?

Let us see command line syntax to run bash shell aliases using the ssh command under Linux.
Bash aliases not running or working over ssh client on Unix based system
To solve this problem run ssh command as follows:

$ ssh -t user@remote /bin/bash -ic 'your-alias-here'

Where ssh command options:
-t : Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful. Without the -t option passed to the ssh, you will get an error that read as "bash: cannot set terminal process group (-1): Inappropriate ioctl for device. bash: no job control in this shell."
Where bash shell options as follows:
-i : Make the shell is interactive so that it can run bash aliases
-c : Commands are read from the first non-option argument command_string.


[Need urgent assistance with Linux related queries? We can help you today.]


Conclusion

This article will guide you on how to run commands and bash shell aliases on a remote machine using the ssh command.