Check for Existing SSH Keys
You may already have an SSH key pair generated on your machine. To see whether you have SSH keys on the system, run the command:
ls -al ~/.ssh/id_*.pub
Generate SSH Key Pair
1. The first thing you need to do is generate an SSH key pair on the machine you are currently working on.
command is:
ssh-keygen -t rsa
Upload Public Key Using the ssh-copy-id or SFTP/SSH with Cat Command.
Option 1. Using the ssh-copy-id Command
Connect to the remote server and use the ssh-copy-id
command, The public key is then automatically copied into the .ssh/authorized_keys file.
ssh-copy-id
command:
ssh-copy-ide [remote_username]@[server_ip_address]
Option 2. Using The sftp with cat command :
sftp [remote_username]@[server_ip_address]
sftp> cd .ssh
sftp> put id_rsa.pub
Now login remote server :
cd .ssh
cat id_rsa.pub >> authorized_keys
Option 3. Using SSH with cat command :
cat .ssh/id_rsa.pub | ssh [email protected] ‘cat >> .ssh/authorized_keys