Skip to content

Instantly share code, notes, and snippets.

@Tantas
Last active August 29, 2015 14:04
Show Gist options
  • Save Tantas/d77d67fc21e8a6871885 to your computer and use it in GitHub Desktop.
Save Tantas/d77d67fc21e8a6871885 to your computer and use it in GitHub Desktop.
Guide to create and install an RSA key onto a remote machine.
#!/bin/bash
# Create an rsa key and install on a remote machine.
echo "This is a guide. Do not execute this as a script."
exit -1
# Create a new rsa key and deploy to a server. Make sure to add a password.
ssh-keygen -t rsa -C "username@host"
# Prepare the ssh directory on the host.
ssh username@host
mkdir -p ~/.ssh
touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
# Move the key to the server.
cat key.pub | ssh username@host 'cat - >> ~/.ssh/authorized_keys'
# Alternative move method, 'brew install ssh-copy-id'
ssh-copy -i key.pub username@host
# Log in once using the key.
ssh username@host -i private_key
# Apply the password and should be able to log in without a password.
# Useful reference resource.
# https://kb.mediatemple.net/questions/1626/Using+SSH+keys+on+your+server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment