Skip to content
3
Using Public Keys
4
Using Private Keys
5
Completed

Step 3: Uploading public key

In the previous step we've created your public () and private () keypair. In this step we'll focus on the public () key and on how to install this on the Server ().

We previously created an SSH key pair using MobaXterm. Now, we'll upload the Public Key () to the remote Server (): hpc.tue.nl, to enable key-based authentication.

Steps to Upload Your SSH Public Key:

  1. Open MobaXterm:

    Open MobaXterm by double-clicking its icon on your desktop or finding it in your Start menu, or by continuing with an existing session if one is already open.

  2. Connect to the Remote System:

    Start an SSH session in MobaXterm:

    1. Click on the "Session" button in the top menu.
    2. Choose "SSH" from the session type options.
    3. Enter the following details:
      • Remote host: hpc.tue.nl
      • Username: Enter your username for the server.
    4. Click "OK" to connect using your current password credentials.
  3. Prepare the .ssh directory on the Server ():

    Once connected, ensure the .ssh directory exists:

    mkdir -p ~/.ssh
    
  4. Transfer the Public Key ():

    • After establishing the connection, MobaXterm will display a file navigator on the left side.
    • Use this file navigator to find your public key file, id_rsa.pub, on your local machine in the location you saved it during the Generate Keypair (2) step.
    • Drag and drop the id_rsa.pub file into the .ssh directory located within your home folder on the remote server.

      Are you not seeing the .ssh folder in the file navigator?

      Ensure you've performed previous step:

      mkdir -p ~/.ssh
      

      If you still don't see the .ssh directory click on the Refresh Folders () button:

      img.png

  5. Add the Public Key () to authorized_keys:

    • In the SSH terminal, append the public key to the authorized_keys file:
      cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
      
    • Alternatively, open the authorized_keys file in an editor and paste the contents of id_rsa.pub.
  6. Set Correct Permissions:

    Set appropriate permissions for the .ssh directory and authorized_keys file:

    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    

We previously created an SSH key pair using a terminal on Windows. Now, we'll upload the Public Key () to the remote Server (): hpc.tue.nl, to enable key-based authentication.

Steps to Upload Your SSH Public Key:

  1. Open PowerShell:

    You can start PowerShell by searching for it in the Start Menu and selecting it, by pressing Win + X and choosing "Windows PowerShell" from the menu, or by continuing with an existing session if one is already open.

  2. Use scp or manually copy the Public Key ():

    Unlike ssh-copy-id available on Linux, on Windows, you typically use scp to manually copy the public key over to the server:

    scp C:\Users\yourusername\.ssh\id_rsa.pub username@hpc.tue.nl:~/
    

    Replace yourusername with your Windows username and username with your actual username on the server. This command will securely copy your public key (C:\Users\yourusername\.ssh\id_rsa.pub) to your home directory on the remote server.

  3. Append the Public Key to authorized_keys on the Server:

    After copying the key, you'll need to log in to the remote server to append your public key to the authorized_keys file:

    ssh username@hpc.tue.nl
    

    Once logged in, execute the following commands:

    mkdir -p ~/.ssh
    cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
    rm ~/id_rsa.pub
    chmod 600 ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
    

    These commands will ensure that your public key is added to the authorized_keys file and that the permissions are set correctly for SSH key-based authentication.

We previously created an SSH key pair using a terminal on Linux. Now, we'll upload the Public Key () to the remote Server (): hpc.tue.nl, to enable key-based authentication.

Steps to Upload Your SSH Public Key:

  1. Open a Terminal:

    Start your terminal application. You can typically find it in the application menu or use a keyboard shortcut (e.g., Ctrl + Alt + T on some systems), or by continuing with an existing session if one is already open.

  2. Use ssh-copy-id to Transfer the Public Key ():

    Use the ssh-copy-id command to transfer your SSH Public Key () from its default location to the remote Server (), hpc.tue.nl:

    ssh-copy-id -i /home/yourusername/.ssh/id_rsa.pub username@hpc.tue.nl
    

    Replace username with your actual username on the server. This command will securely copy your public key (/home/yourusername/.ssh/id_rsa.pub) to the remote server and append it to the authorized_keys file automatically.

We previously created an SSH key pair using the Terminal on macOS. Now, we'll upload the Public Key () to the remote Server (): hpc.tue.nl, to enable key-based authentication.

Steps to Upload Your SSH Public Key:

  1. Open a Terminal:

    Launch the Terminal by navigating to Applications > Utilities > Terminal, or use Spotlight Search (⌘ + Space) and type "Terminal," then hit Enter, or by continuing with an existing session if one is already open.

  2. Use ssh-copy-id to Transfer the Public Key ():

    Use the ssh-copy-id command to transfer your SSH Public Key () from its default location to the remote Server (), hpc.tue.nl:

    ssh-copy-id -i /Users/yourusername/.ssh/id_rsa.pub username@hpc.tue.nl
    

    Replace username with your actual username on the server. This command will securely copy your public key (/Users/yourusername/.ssh/id_rsa.pub) to the remote server and append it to the authorized_keys file automatically.

Next step

After following all the provided instructions of this step you succesfully added your Public Key () to the Server (). Congratulations!

In the next step of this guide we'll continue with using the earlier generated Private Key () to access the Server ().

Continue