ssh user@<remote_server> 'command1' ssh user@<remote_server> 'command2' ssh user@<remote_server> 'command1 | command2'
Replace the user with the existing user on the remote server and replace the <remote_server> with your server IP or fqdn hostname. The ssh client will login to the remote server and run the command you specified.
Here’s some examples on running commands over ssh:
- Get remote server date and time:
ssh user@remote_server date
- Find out remote server disk space usage:
ssh user@remote_server 'df -H'
- Find out remote server kernel version and Linux distro names:
ssh user@remote_server 'uname -mrs'
OR
ssh user@remote_server 'lsb_release -a'
- Run a remote script called /scripts/backup.sh to perform backup:
ssh user@remote_server '/scripts/backup.sh'
Here, the backup script must exist on the remote server and is executable, we must use the full path of the remote script.