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 user@gamma.example.com "netstat -tulpna|grep -i established"
user@gamma.example.com's password: *****
...Output...

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

Be Sociable, Share!

    Published by

    admin

    Lovable, friendly and crazy 25-year-old-boy.