Skip to content

Instantly share code, notes, and snippets.

@genghisjahn
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genghisjahn/5aee5df5024718bbb3b6 to your computer and use it in GitHub Desktop.
Save genghisjahn/5aee5df5024718bbb3b6 to your computer and use it in GitHub Desktop.
How to copy local SSH public key to a server.

Use this so you can SSH into a VM you just made.

On the HOST

For Virtual Box: Put Network Settings from NAT to Bridged Adapter the Host VM. To start headless : Hold shift down and clic start button

On the server you will be SSH'ing into:

sudo apt-get install openssh-client # incase you want to ssh from the VM at some point.

sudo apt-get install openssh-server

Once the above are installed:

sudo /etc/init.d/ssh restart

Make sure the .ssh directory exists in the home directory of the user you will be logging on as.

On the client you will SSH From

This is if the authorized_keys file DOES NOT exist:

On the server: mkdir ~/.ssh

On the client scp ~/.ssh/id_rsa.pub {username}@{IP Address or DNS Name}:~/.ssh/authorized_keys

If authorized keys DOES exist:

cat ~/.ssh/id_rsa.pub | ssh {username}@{IP Address or DNS Name} "cat - >> ~/.ssh/authorized_keys"

Then make sure permissions are correct:

chmod 0700 ~/.ssh

chmod 0600 ~/.ssh/authorized_keys

When you're all done, add the connection info to your ~/.ssh/config file.

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