Translation(s): English - ?Fran├žais - Italiano

ToDo: merge (and translate) this page and the french one (more complete)

Introduction

SSH stands for Secure Shell and is a protocol for secure remote login and other secure network services over an insecure network1. See Wikipedia - Secure Shell for more general information and ssh, lsh-client or dropbear for the SSH software implementations out of which OpenSSH is the most popular and most widely used2. SSH replaces the unencrypted telnet,rlogin and rsh and adds many features.

In this document we'll be using the OpenSSH command suite, it will also be assumed that the following two variables are defined:

remote_host=<the remote computer>
remote_user=<your user name on $remote_host>

So, if you want to use the recipes below, first set these variables to the remote computer name and the user name on that remote computer. Then cut and paste of the commands below should work. remote_host may also be an IP-address.

Installation

Installation of the client

Normally the client is installed by default. If not it suffices to run as root:

aptitude install openssh-client

Installation of the server

The server allows to connect remotely and gets installed by running as root:

aptitude install openssh-server

Configuration files

The main configuration files are in the directory /etc/ssh :

In addition this directory contains the private/public key pairs identifying your host :

Remote login

If you want to login to $remote_host as user $remote_user simply type

ssh $remote_user@$remote_host

If the usernames on the local and the remote computer are identical, you can drop the $remote_user@-part and simply write

ssh $remote_host

If this is the first time you login to the remote machine, ssh will ask you whether you are sure you want to connect to the remote computer. Answer 'yes' and then type in your password, and ssh will do a remote login for you.

Remote commands

If you just want to run one command on the remote computer, you don't need to login. You can tell ssh to run the command without login, for instance,

ssh $remote_user@$remote_host 'ls *.txt'

lists all files with extension .txt on the remote computer. This works with single tick quotes '...' as shown here, with double tick quotes "...", and without quotes. There may be differences between these three cases, though, not yet documented here.

ssh without password

If you work on a remote computer often, typing in the password each time you use ssh becomes annoying. You can configure ssh such that it does not ask you for a password anymore for that particular connection. You have to generate a private and public encryption key on your local machine and provide the public key to the remote machine.

To generate the keys run

ssh-keygen

and reply to all questions just with return.

To provide the public key to the remote machine first create there an .ssh directory (if not present already) and then append the public key of your local machine to the authorized_keys file on the remote machine.

ssh $remote_user@$remote_host mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh $remote_user@$remote_host 'cat >> .ssh/authorized_keys'

Note that here the cat command within the ssh command takes its input from the pipe.

or you can use

ssh-copy-id -i ~/.ssh/id_rsa.pub $remote_user@$remote_host

From now on, you should be able to login with ssh without password.

SSH into Debian from another OS

SSH and security

SSH Server

SSH Client