Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.

The Secure SHell (SSH) protocol is used to securely access remote servers. SSH secures information with the use of a private and public key. The public key is like a lock, anybody can see it but only the person with the private key can unlock it. So when you connect to the remote server, the server confirms your identity by seeing if your private key unlocks the lock. This checking continues as information is sent to you from the server. The private key should be kept private (hence the name); anybody who has the private key can impersonate the person who generated it and steal their private information. Not only do SSH keys help to protect your data, they add convenience. Instead of entering your RIT password (which you have to change at least once a year) every time you SSH into a remote machine, you can enter the passphrase for a private SSH key (which you never have to change).

Key Generation and Set up with Linux / Mac / Windows with MobaXterm

NOTE: These images are from using MobaXterm on Windows. Mac and Linux will look slightly different but follow the same process.

  1. Open the terminal/command prompt on your computer (for Windows open terminal in MobaXterm).
  2. In the command line run:
    ssh-keygen -t rsa

    Image Removed

  3. The terminal will respond with:
    Generating public/private rsa key pair.
    Enter file in which to save the key ( /home/RITusername/.ssh/id_rsa):
    The default file is usually fine. Hit enter to continue.
    Image Removed
  4. Next it will prompt you to enter a passphrase and confirm it. Do not leave it empty. Make sure to remember this password for later. (NOTE: The terminal will not show the password while typing. This is to prevent others from seeing your password).

    Enter passphrase (empty for no passphrase):
    Enter the same passphrase again:

    Image Removed

  5. Now it will tell you where your key pair was saved:

    Your identification has been saved in /home/username/.ssh/id_rsa
    Your public key has been saved in /home/username/.ssh/id_rsa/pub

    The identification is your private key. You can open these files in a text editor (e.g. nano /home/username/.ssh/id_rsa/pub)  and see the keys. The fingerprint of the key and it’s randomart image is also displayed. These are used to help recognize keys.

    Image Removed

  6. To add the key to the remote server run:

    [abc1234@computer ~] ssh-copy-id -i .ssh/id_rsa.pub abc1234@computerhost.rit.edu

    *If the ssh-copy-id command is not available on your machine, skip the following steps and go to the "Alternative to ssh-copy-id heading". 

    Image Removed

  7. The terminal may show you the key fingerprint and ask if you still want to install it. If so, type yes.
  8. Next the terminal will ask you to enter your password for the remote machine.
  9. Now the terminal will say that a key was added and ask you to try logging into the machine you just copied the public key to. If all is right you will not have to enter your RIT password, but instead the passphrase for the key generated.
    Image Removed
  10. To circumvent entering your passphrase every time you SSH into a machine, you can use the ssh-agent command that will enter the passphrase for you. See the "Using ssh-agent heading".

Alternative to ssh-copy-id

The ssh-copy-id command may not be available on older versions of the Mac OS. To install this command on your Mac follow the instructions provided here: https://www.ssh.com/ssh/copy-id#sec-Ssh-copy-id-on-Mac

If you do not want to or cannot install the shh-copy-id command use this alternative. It does the same thing as ssh-copy-id.

  1. Run this command in your terminal:

    [abc1234@computer ~] cat ~/.ssh/id_rsa.pub | ssh abc1234@computerhost.rit.edu "cat - >> ~/.ssh/authorized_keys"
  2. You will then be prompted to enter your RIT password for the remote machine.
  3. Next time you log into the remote machine you will be prompted to enter the passphrase for the private key and then you will be able to access the machine.

Key Generation and Setup on Windows with PuTTY

...

If the .ssh file has not been created type the code below. In the picture below, the user has already created the .ssh file. Because of this, the compiler throws a message that the file already exists.

mkdir ~/.ssh
chmod 700 ~/.ssh

Image RemovedImage Removed

...

If the authorized_keys file does not exists:

touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

Image Removed

...

Open the authorized_keys file with a text editor of your choice (the command below opens the key in vim):
vim ~/.ssh/authorized_keys

Image Removed

A window similar to this will pop up. It is the authorized_keys file in the vim text editor within PuTTY.
Image Removed

...

Copy the public key from the PuTTYgen window and paste it to the end of the authorized_file. The way PuTTYgen saves their public keys is not compatible with the authorized_keys format so you cannot copy and paste from the public file itself. You must open it from the PuTTYgen window by clicking Load, selecting the corresponding private key, and entering the passphrase.

Click on "Load":
Image Removed

Select private key from your files:
Image Removed

Enter your passphrase:
Image Removed

Copy key from PuTTYgen window:
Image Removed

...

Paste key at the end of the authorized_keys file opened in vim:
Image Removed

...

Save the authorized_keys file and log out of the terminal. Commands for text editors (such as how to save in vim) are located here. To save and exit out of the authorized_keys file in vim type ESC, and then :wq (save and quit). It will return you to the regular PuTTY terminal from before you opened the authorized_keys file.

...

Image Removed

...

Click Browse and find where you stored the private key that corresponds to the public key you just pasted into authorized_keys.

...

Go back to the Session tab and enter information as you would regularly.

Image Removed

...

When the terminal is open it will say:

Authenticating with public key “rsa-key-######”
Passphrase for key “rsa-key-#####”

...

Enter the passphrase for the key and you are set.

To avoid entering your passphrase every time you use PuTTY for SSH, you can use PuTTY's Pageant. Instructions for Pageant are under the Pageant and Desktop FastX heading.

TortoiseGit (Windows)

  1. Follow the instructions above to generate and save your SSH keys
  2. Open File Explorer and navigate to the folder containing your repository
  3. Right-click on your repository folder and select "TortoiseGit", then "Settings"
    Image Removed
  4. Click "Git", then "Remote"
  5. Select "origin" on the right side of the window
  6. Click the three dots next to "Putty Key":
    Image Removed
  7. Select your private key from your files:
    Image Removed
  8. Click "Apply"
  9. Click "OK"

FastX Web Client

Windows with PuTTY Setup

FastX does not support PuTTY's format for private SSH keys, so we need to first convert them into OpenSSH format.

  1. You must have the public key already on the remote machine. Follow the key generation and setup instructions for Windows with PuTTY.
  2. Open PuTTYgen and click Conversions → Import Key in the top menu bar.
    Image Removed
  3. Find the private key you want to convert
    Image Removed
  4. Enter the passphrase for the key
  5. Click the Conversions → Export OpenSSH key
    Image Removed
  6. Save this key as something you will recognize as being the export key
  7. You can exit the PuTTYgen window

Now we are ready to use SSH keys with FastX

...

Using Pageant (Windows)

Pageant is a tool included with PuTTY that runs as a background process and enters the passphrase for the private keys for you. If you are using MobaXterm you cannot use the key generated by ssh-keygen, you must use the generator which is found under Tools →  MobaKeyGen. MobaKeyGen is very similar to PuTTYgen, so you can use the instructions under Key Generation and Set up on Windows with PuTTY.

...

Using ssh-agent (Mac / Linux / MobaXterm)

The ssh-agent is a background process that automatically enters the passphrase for private keys. You must have at least one key already set up on your computer. Follow the instructions under Key Generation and Set Up with Linux / Mac / MobaXterm to do this.

  1. Open your terminal and starting the program by running:
    eval `ssh-agent`

    Note: Backquote (`) is located under tilde (~), the backquote is not a single quote (')
    Image Removed

  2. Next add the private key to the agent:
    ssh-add

    Image Removed

  3. You will then be asked to enter the passphrase for the private key.
  4. Now you can connect through FastX as you normally would without entering your RIT password or passphrase for the private key.
  5. When you are done using FastX and SSH into the terminal type:
    kill $SSH_AGENT_PID 
    Image Removed
    You can add this command to your .bash_logout file (for bash users) or .logout (for csh or tcsh users) so that it happens automatically when you log out.

FastX Desktop Client and SSH Keys

You can use SSH keys on FastX as well. When you use the keys with FastX, you will not have to enter your RIT password or your passphrase. This is because you will be using Pageant or ssh-agent that enters the keys for you. Simply have ssh-agent or Pageant running in the background while you run FastX. Make sure to end those processes when you are done with FastX.

If there are any further questions, or there is an issue with the documentation, please contact rc-help@rit.edu for additional assistance.This wiki page is deprecated. You can find this documentation on our new documentation site: https://research-computing.git-pages.rit.edu/docs/creating_and_using_ssh_keys.html