Copy rsa public key to remote server

Establish a secure connection via ssh

This rsa public key displayed on your local computer also need to be copied to your remote computer to establish a secure connection via ssh. There are various methods to do so:

1) Copying Public Key Using ssh-copy-id

2) Copying Public Key Using SSH

3) Copying Public Key Manually

Windows PowerShell does not support all the commands. Methods 1 and 3 may not work on PowerShell but it will definitely work on Ubuntu. Here we will be using method 2 on PowerShell. For details on all the methods you can check the tutorial here.

So by method 2 use the following command on your local computer to copy the rsa public key to your remote computer:

cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys" 

Enter your username and remote server ip address on 'username@remote_host'. Here we use 'rocket@5.189.149.230'

You need to enter password of your remote server with user/login as 'rocket'.

Also you need to enter passphrase for the rsa public key on your local computer.

You are now logged in as user 'rocket' on your remote server

Now let's check the hidden files and folders with command:

 ls -a 

.bash_history .bash_layout .bashrc .cache .local .profile .ssh .sudo_as_admin_successful

Now let's check contents of the folder .ssh :

cd .ssh
ls

authorized_keys

sudo nano authorized_keys

This is the same key as in you local computer 'rsa.pub'.

Last updated