Install OpenSSH

OpenSSH is a collection of applications that enable secure remote communication with your Linux server using the ssh protocol. This is used primarily for secure remote shell access and file transfer. The most secure current authentication method is via public key authentication, which is far superior to username and password authentication.

The following tutorial will walk you through the installation and configuration of OpenSSH server on Ubuntu Server 10.04 LTS.  We will then walk through configuring a remote guest system for secure public key authentication to the host server.

Refer to the OpenSSH section of the Ubuntu Server Guide for detailed installation and configuration instructions.

Server Installation and Configuration

Install the OpenSSH server on the host system (your Drupal server):

sudo apt-get install openssh-server

Secure the OpenSSH server configuration on the host system:

#Backup the base configuration file
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.defaults

#Make the backup copy read only
sudo chmod a-w /etc/ssh/sshd_config.defaults

#Open the active config file in a text editor
sudo nano /etc/ssh/sshd_config

Uncomment and set the following values:

#Enable RSA authentication
RSAAuthentication yes

#Enable public key authentication
PubkeyAuthentication yes

#Disable password authentication
PasswordAuthentication no
#Disable Pluggable Authentication Module support
UsePAM no

Restart the OpenSSH server to load the new configuration:

sudo /etc/init.d/ssh reload

Client Installation and Configuration

Install the OpenSSH client if it is not already present on the client system:

sudo apt-get install openssh-client

Generate public and private keys:

ssh-keygen

Your private and public keys will be stored in the following locations by default:

~/.ssh/id_rsa
~/.ssh/id_rsa.pub

Enter and verify a passphrase for additional security

Copy the public key to the authorized_keys file on the remote host:

ssh-copy-id username@remotehost

[Note: for this step to work you must temporarily enable password authentication on the host server. See step 3 in Server Installation and Configuration above. Alternately, you can manually add additional keys to the "~/.ssh/authorized_keys" file on the host server.]

Test your configuration by remotely logging in to the remote host system from the guest system:

ssh user@remotehost

You should now be able to login to the remote host using only the passphrase you created when you generated your public and private keys. Repete these steps on a remote clients from which you wish to connect to your host server.

Additional Information

It is very important to ensure that OpenSSH server is securely configured. To learn more about configuring OpenSSH on Ubuntu Server, check out the following:

Find an error? Know a better way? Please leave a comment and help improve this cookbook.