Client Use

There are a few preliminaries to get out of the way. First stop is key generation.

Generating SSH Client Keys

Before we can really use the power of SSH, we need to generate keys for the user account. We do this by using the ssh-keygen command:

[joe@client.acme]: ssh-keygen -t ed25519
  Generating public/private key pair.
  Enter file in which to save the key (/home/joe/.ssh/id_ed25519):
  Enter passphrase (empty for no passphrase): **********
  Enter same passphrase again: **********
  Your identification has been saved in /home/joe/.ssh/id_ed25519.
  Your public key has been saved in /home/joe/.ssh/id_ed25519.pub.
  The key fingerprint is:
  da:07:3f:49:a3:b6:65:da:06:c7:53:9f:b6:28:06:0f joe@astro.acme

You should now see the public and private ed25519 keys ~/.ssh/id_ed25519.pub and ~/.ssh/id_ed25519:

[joe@client.acme]: ls -l .ssh/
 total 8
 -rw-------    1 joe  users   736 Apr 28 23:30 id_ed25519
 -rw-r--r--    1 joe  users   609 Apr 28 23:30 id_ed25519.pub

The file ~/.ssh/id_ed25519.pub contains the DSA public key for authentication. The contents of this file should be added to ~/.ssh/authorized_keys on all machines where the user wishes to log in using public key authentication. There is no need to keep the contents of this file secret.

Once distributed, ssh will perform a random number challenge based on the public key, which the originating client must decrypt using the private key. This all happens transparently to you, but the result is that no passwords or passphrases are directly sent over the network, even in encrypted form.

Let us test this by copying ~/.ssh/id_ed25519.pub to your remote server and putting the contents into the ~/.ssh/authorized_keys files:

[joe@client.acme]: scp ~/.ssh/id_ed25519.pub server.acme:.ssh/authorized_keys
 Are you sure you want to continue connecting (yes/no)? yes
 Permanently added 'server.acme,192.168.0.109' (DSA) to known hosts
 joe@server.acme's password:
 id_ed25519.pub           100% |******************|   609       00:00

Now we can test this out by trying to ssh into the server. We expect now to be asked for the passphrase and NOT the password (note we change the prompt to emphasize the user and host):

[joe@client.acme]: ssh server.acme
 Enter passphrase for key '/home/joe/.ssh/id_ed25519': ********

[joe@server.acme]: hostname
 server.acme

It works! So far so good. Lets do some exercises and then talk about typcial ssh applications.

Exercise:

  • Why is passphrase authentication better than password authentication?

  • (hard) Use ethereal to try to see what is being sent in the ssh challenge. Report your findings below.

Now that the heavy lifting is out of the way, we can finally use SSH to do some encrypted communications. We will go through the most common uses in their order of complexity.

Exercises

  1. The simplest of commands is to connect to remote host as before:

    [joe@client.acme]: ssh server.acme
    Enter passphrase for key '/home/joe/.ssh/id_ed25519': ********
    
  2. Next we connect to remote as another user using user@server.acme. Ask your neighbor to set up an account for joe with password “joejoe”. Note that since you dont have your public key there yet, you have to use a password.:

    [joe@client.acme]: ssh joe@server.acme
    joe@server.acme's password: ********
    
  3. Install your public key on joe@server.acme as above and try again using passphrases.