Skip to content

Instantly share code, notes, and snippets.

@chales
Last active December 16, 2015 16:29
Show Gist options
  • Save chales/5463274 to your computer and use it in GitHub Desktop.
Save chales/5463274 to your computer and use it in GitHub Desktop.
Short command to push your key if you do not have ssh-copy-id (such as on OSX).Via terminal this will copy your public key (id_rsa.pub assumed) to a remote server and push it into the authorized_keys file. At that point you should be able to login without being prompted for the password for the remote system.
# Copy your public key (id_rsa.pub assumed) to a remote server and push it into
# the authorized_keys file.
# An assumption is your key is named "id_rsa" so make sure that is correct.
cat ~/.ssh/id_rsa.pub | ssh [email protected] 'cat >> ~/.ssh/authorized_keys'
# What about not having a ~/.ssh directory already on the remote host? You
# would be better off logging into the remote machine and doing a 'ssh localhost'
# there which will create the directory with proper permissions. You can give
# this a try but if you run into a login issue it's likley permission based.
# Create the .ssh directory and the authorized_keys file.
cat ~/.ssh/id_rsa.pub | ssh [email protected] 'mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys'
# The authorized-keys file will need permissions set to 0600 (user read and write only)
# Example if you have an alternate port number.
cat ~/.ssh/id_rsa.pub | ssh [email protected] -p2222 'cat >> ~/.ssh/authorized_keys'
# Example if you have an alias for "example" setup in your ssh config.
cat ~/.ssh/id_rsa.pub | ssh example 'cat >> ~/.ssh/authorized_keys'
@chales
Copy link
Author

chales commented Nov 21, 2013

Note for OSX users that have Homebrew installed you can install the copy id utility with: brew install ssh-copy-id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment