To copy the new public key to the target system, you can use the ssh-copy-id command or manually append it to the authorized_keys file. Here are both methods:
Method 1: Using ssh-copy-id
-
Run the following command:
ssh-copy-id username@target_hostReplace
usernamewith your username on the target system andtarget_hostwith the IP address or hostname of the target system. -
Enter your password when prompted. This command will automatically copy your public key to the
authorized_keysfile on the target system.
Method 2: Manually Copying the Public Key
-
Display your public key:
cat ~/.ssh/id_rsa.pub -
Copy the output of the public key.
-
SSH into the target system:
ssh username@target_host -
On the target system, open or create the
authorized_keysfile:mkdir -p ~/.ssh nano ~/.ssh/authorized_keys -
Paste the public key into the
authorized_keysfile. Save and exit the editor. -
Set the correct permissions for the
authorized_keysfile:chmod 600 ~/.ssh/authorized_keys
After completing these steps, you should be able to SSH into the target system without needing to enter a password.
