Secure encrypted communications using OpenSSH

nas

OpenSSH is an implementation of SSH (secure shell) which is used for secure communication between two machines (a client and a server). OpenSSH is the best tool you can use for secure data transfer. Below, we'll run through how you can start using it for your data transfer needs.

Reading time:
2 min

OpenSSH

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:

ssh -V

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:

ssh username@hostname

For example:

You could also use:

ssh -l username hostname

For example:

ssh -l tutonics 192.168.0.7

Running a remote command

You can run a command on the remote machine using:

ssh username@hostname '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 username@server '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.

Thank you for reading this article.
Please share if you liked it.