Secure Shell - use SSH to execute a remote command

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search

You'll need to be able to ssh with automated password or enter the password each time you run the command.

Execute a remote command on a host over SSH:

ssh nicolep@192.168.100.10 'reboot'

The example above will reboot the remote computer.

Multiple commands

ssh nicolep@192.168.100.10 'uptime; df -h'

Show the kernel version, number of CPUs and the total RAM:

ssh root@192.168.100.10 << EOF
uname -a
lscpu  | grep "^CPU(s)"
grep -i memtotal /proc/meminfo
EOF

Here is how Nicole can execute her script on the remote computer

ssh nicolep@192.168.100.10 'bash -s' < nicolejob.sh

Nicole's script is local on her machine, and she executed it on the remote host.