Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How to append authorized_keys on the remote server with id_rsa.pub key from the local machine with a single command?

like image 803
shilovk Avatar asked May 11 '14 09:05

shilovk


People also ask

What type of keys would you add to authorized_keys file?

The authorized_keys file in SSH specifies the SSH keys that can be used for logging into the user account for which the file is configured. It is a highly important configuration file, as it configures permanent access using SSH keys and needs proper management.

How do you I add a second key to the authorized_keys file?

There is already a command in the ssh suite to do this automatically for you. I.e log into a remote host and add the public key to that computers authorized_keys file. If the key you are installing is ~/. ssh/id_rsa then you can even drop the -i flag completely.


2 Answers

ssh-copy-id user@remote_server

http://linux.die.net/man/1/ssh-copy-id

like image 69
Doug Avatar answered Sep 22 '22 21:09

Doug


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" 
like image 40
Mose Avatar answered Sep 24 '22 21:09

Mose