SSH: Simple CLI function to add keys to server.
This is how I quickly add SSH keys to any remote server. I always found myself messing up the cat
syntax when adding keys. This function just takes your SSH user@hostname
, and assuming your authorized_keys
file exists on the server, adds your public key.
function add-ssh-keys() {
cat ~/.ssh/id_rsa.pub | ssh $1 'cat >> ~/.ssh/authorized_keys'
}
Simply add this to your .zshrc
or .bash_profile
file, and restart your session or reload the profile.
Usage:
add-ssh-keys root@myhostname
You will be prompted to enter the password for your user, and your'e good to go.
Written by Jon Lunsford
Related protips
2 Responses
Thank you for your tip! I preferred to use ssh-copy-id
.
over 1 year ago
·
Thanks! Yes, ssh-copy-id
is much more robust.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Command line
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#