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:
-
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.
-
Connect to the Remote System:
Start an SSH session in MobaXterm:
- Click on the "Session" button in the top menu.
- Choose "SSH" from the session type options.
- Enter the following details:
- Remote host:
hpc.tue.nl
- Username: Enter your username for the server.
- Remote host:
- Click "OK" to connect using your current password credentials.
-
Prepare the
.ssh
directory on the Server ():Once connected, ensure the
.ssh
directory exists:mkdir -p ~/.ssh
-
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.
-
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 ofid_rsa.pub
.
- In the SSH terminal, append the public key to the
-
Set Correct Permissions:
Set appropriate permissions for the
.ssh
directory andauthorized_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:
-
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.
-
Use
scp
or manually copy the Public Key ():Unlike
ssh-copy-id
available on Linux, on Windows, you typically usescp
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 andusername
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. -
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:
-
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. -
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 theauthorized_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:
-
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.
-
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 theauthorized_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 ().