Let's say we want to configure an ssh
connection between machine alpha and beta.
- Go to your home folder at machine alpha:
$ cd ~
- Run the
ssh-keygen
command:
$ ssh-keygen
The command will ask you for two things:
- Location of the keys; enter the full path (e.g.,
/home/<user>/.ssh/<user@machine>
- Passphrase; enter it.
The command will create two keys: private (<user@machine>
) and public <user@machine>.pub
.
Note - the .ssh
directory must have drwx------
permissions; the private key must have -rw-------
permissions; and the public key must have -rw-r--r--
permissions. You can modify the permission chmod
command.
- Move the public key (with
.pub
extension) to the directory/home/<user>/.ssh/
on machine beta (e.g. using USB key)
Note - if the /home/<user>/.ssh/
directory does not exist on machine beta, create it by mkdir
command. Again, permissions must be drwx------
.
- Go to the
.ssh
directory and copy the content of the public key into theauthorized_keys2
file:
$ cat <user@machine>.pub >> authorized_keys2
- Go back to the machine alpha and create a
config
file in the/home/<user>/.ssh/
directory by your favourite text editor (nano, vim, etc.):
$ cd ~
$ cd .ssh
$ nano config
The content of the config
file should look like this:
Host <beta>
User <user>
Identityfile ~/.ssh/<user@machine>
Note - the config
file must have -rw-r--r--
permissions.
Let's say we want to configure an ssh
connection between Windows machine win and UNIX machine unix.
-
On the win, download and install
Putty
application. -
Open
PuttyGen
(part ofPutty
) and generate RSA public and private keys.
Note - you should consider to set a passphrase.
-
Move the public key to the UNIX machine unix and save it to
/home/<user>/.ssh/
-
Make sure that the public key has
-rw-r--r--
permissions. -
Convert the public key to OpenSSH format, details here:
$ ssh-keygen -i -f publicKeyRSA > publicKeyRSA_pub
- Copy the content of the public key into the
authorized_keys2
file:
$ cat <user@machine>.pub >> authorized_keys2