To connect to a server, use the SSH command, along with the server user and IP address
ssh username@12.34.56
To generate a SSH key, use the ssh-keygen command
ssh-keygen
There are two ways to add your SSH Key to your remote server
- Go to your remote server
- Go to your
.ssh
directory, which is likely in your home directory. Create it if it doesn't existcd ~/.ssh
- Create a file named authorized_keys there within
- Paste your public key that will be used to connect to that server. The private key stays in your server/machine
- Restart your connection
- The second, and more effecient way is by using the
ssh-copy-id
command ssh-copy-id -i ~/.ssh/my_key.pub username@12.34.56
- in this command we use the -i flag to specify the public key we want to add to our remote server
- the next part of the command is the path to the public key
- and the final part is the remote server in which we want the public key to be added
- this yields the same exact result as method #1 (you will see an authorized_keys file with your public key within)