Apr 30, 2022

Running Commands Over SSH

Running commands on a remote server vi SSH is common nowadays. For example:

  • Get the file system and disk info
  • Get user info
  • Get all the running process

 

The syntax is as follows:

$ ssh xx@192.168.31.215 command1

$ ssh xx@192.168.31.215 -- command1 -arg1 -arg2

$ ssh xx@192.168.31.215 -- "command1 && command2"

$ ssh xx@192.168.31.215 -- command1 -arg1 > /tmp/local.out

$ ssh -t xx@192.168.31.215 -- sudo command1 -arg1 -arg2

 

The double dash “--“, means “end of command line flags.” It tells ssh not to try to parse what comes after command line options.

The -t option needed when using sudo command over ssh.


Links: