Running Commands on a Remote Linux Server over SSH

In this note you will find the examples of how to execute commands on a remote Linux machine and get the result locally.

This information may be very useful if you are creating some Bash Script that should be ran from the local machine and execute some commands on a remote server.

You'll learn, how to :

  • execute a command on a remote Linux Server;
  • run multiply commands over SSH;
  • execute a local script on a remote Linux server without copying it.

You may also be interested in the following articles :

Running a Command on a Remote Linux Server

$ ssh [user]@[server] '[command]'

Get the uptime of the remote server

$ ssh root@ 'uptime'

Reboot the remote server

$ ssh root@ 'reboot'

Running Multiply Commands over SSH


$ ssh [user]@[server] '[command 1]; [command 2]; [command 3]'

Get Uptime and Disk Usage

$ ssh root@ 'uptime; df -h'


$ ssh [user]@[server] '[command 1] | [command 2] | [command 3]'

Get Memory Usage and Load Average

$ ssh root@ 'free -m | cat /proc/loadavg'


$ ssh [user]@[server] << EOF
command 1
command 2
command 3

Show Kernel Version, CPU(s) info and Total RAM seen by the system

$ ssh root@ << EOF
uname -a
grep "model name" /proc/cpuinfo
grep MemTotal /proc/meminfo

Executing a Local Script on a Remote Linux Server

$ ssh [user]@[server] 'bash -s' < [local_script]

Execute the Local Script '' on the Remote Machine

$ ssh root@ 'bash -s' <