The server side of the communicting machines needs to be running sshd (secure shell daemon) which listens for and handles incoming connections. The basic usage for ssh is to allow execution of commands on a remote machine. It is also used to provide the underlying secure data transfer for both scp and sftp.
The program ssh (the client side of the connection) is installed by default in most Linux distributions including Ubuntu. To see what version of ssh client you've got installed, run:
The server side (sshd) normally needs to be installed as it's not there by default. Below, we'll run through some basic usage of ssh, these assume the server side has sshd installed. See the installation instructions here.
Logging into a remote machine
To simply login to a remote machine, use:
You could also use:
ssh -l username hostname
ssh -l tutonics 192.168.0.7
Running a remote command
You can run a command on the remote machine using:
ssh [email protected] 'command1;commmand2'
For example to list files in the download directory on the remote machine, use:
ssh [email protected] 'cd ~/Downloads;ls'
Note that if you want several commands to execute on the other box, they must be within the quotes and separated by a semicolon as shown, otherwise only the first command will run remotely, the rest will run locally.
Running a local script on remote machine
If you have a script which resides on your local box (for example
myLocalScript.sh) and you wish to run it on your server, use:
ssh [email protected] 'bash -s' < myLocalScript.sh
SSH client configuration file
The ssh client configuration file is
/etc/ssh/ssh_config. We'll cover some of these options in future ssh tutorials.
Thanks to Tatu Ylonen, Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song for their work with ssh.