How To: Run a Command Quickly on Remote Server using SSH

Linux "Cluster"

When working in a clustered Linux environment containing two or more servers, it is not uncommon to switch back and forth between the hosts. Even if it’s running one command.

SSH is a powerful tool, it can do allot more than act as remote shell or tunnel traffic. One of those features is sending a command string to the server and fetching the output.

Assuming that you have access and privileged user on the remote server, the command works as follows

Example:
~$ ssh [email protected] "netstat -tulpna|grep -i established"
[email protected]'s password: *****
...Output...

For an even more awesome experience, consider authenticating using ssh-key’s.

Leave a Reply

Your email address will not be published. Required fields are marked *