Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Open a terminal window.

  2. Create a key pair.

    Code Block
    ssh-keygen
    1. The following prompt will appear, click Enter to save in the home directory.

    2. If you previously generated a SSH key pair, it may ask you to overwrite it. Be careful when selecting yes. You will not be able to authenticate the previous key and it cannot be reversed.

    3. Enter a passphrase as desired. Then press Enter.

  3. Copy your public key, specifying which user account you have SSH password access to and the IP address.

    Code Block
    ssh-copy-id newuser@ipaddress
    1. If the following prompt appears, type Yes. This prompt is a result of connecting to the host for the first time.

    2. Enter the user’s password when prompted.

    3. Skip to Step 5 if successful.

    4. If prompted an error, please double check that Allow-Password-Authentication was completed.

  4. If you are not able to use ssh-copy-id, an alternative is the following command. Remember to replace newuser and ipaddress.

    Code Block
    cat ~/.ssh/id_rsa.pub | ssh newuser@ipaddress "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
    1. Similarly, if the following prompt appears, type Yes. This prompt is a result of connecting to the host for the first time.

    2. Enter the user’s password when prompted.

    3. If prompted an error, please see the note at the bottom of the pagedouble check Allow-Password-Authentication was completed.

  5. Exit and reopen the terminal.

  6. Connect to the server with the following, where newuser should be replaced with the appropriate user and ipaddress with the IP address of the remote host.

    Code Block
    ssh newuser@ipaddress
  7. [Optional] Once key-based logins are working, you can decide to disable username and password logins for better security.

    1. Edit server’s configuration file.

      Code Block
      sudo vi /etc/ssh/sshd_config
    2. Tap the i or insert key on your keyboard and edit the lines, referenced below:

      Code Block
      [...]
      PasswordAuthentication no
      [...]
      UsePAM no
      [...]
      
    3. To save, press esc, :, w, q, Enter.

    4. Reload the server’s configuration.

      Code Block
      sudo systemctl restart sshd.service