How to append authorized_keys on the remote server with id_rsa.pub key from the local machine with a single command?
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.
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.
ssh-copy-id user@remote_server
http://linux.die.net/man/1/ssh-copy-id
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With