How to Add a Ssh Key to Remote Server

How to append authorized_keys on the remote server with id_rsa.pub key

Adding an authorized key could be one-lined this way (use double-quotes so it's interpreted before sent):

ssh user@server "echo \"`cat ~/.ssh/id_rsa.pub`\" >> .ssh/authorized_keys"

ssh: adding private key to ssh-agent before copying public key to remote server

The "Adding your SSH key to the ssh-agent" documented on GitHub (same on GitLab) is only there if you generate a private SSH key protected by a passphrase (meaning, encrypted)

The idea is that, for a private SSH key used for authenticating to a remote public service like GitHub or GitLab, it is better to have an encrypted key, which makes it less dangerous if said key is leaked.

This is different for a private SSH key used inside a LAN (in your local network): using a passphrase is still a good idea but not mandatory: if the SSH key leak, you still need access to the LAN in order to use it.

Adding public SSH key to a git repository

server should be:

  • the remote user account gituser which created the bare repo
  • the remote server hostname or IP address where the repo was created.

That means server:~gituser/.ssh/authorized_keys will receive Tom public SSH key.

From Tom's workstation, you can add the remote URL to your local repository:

git remote add origin gituser@serverName:/home/gituser/project.git

And push to it.



Related Topics



Leave a reply



Submit