Logging in with a SSH Private Key on Linux/Mac
In this example, we're going to demonstrate how to use a private key to login to a Linux server with a private key. This tutorial will demonstrate how to do this from a Terminal session on OS X, however the steps are identical when using any terminal software on Linux.
All you will need is:
- ssh – SSH client software, comes installed by default
- Your favorite text editor
We will use vim in this example.
Logging in with a private key
Using your favorite text editor, open the file you'd like to keep your private key in. This file can be named whatever you'd like to call it. We'll be calling our key deployment_key.txt:
Paste in the private key and save the file. If you're using vim, once the empty file is opened, press 'i' to get into insert mode, paste the key, press Escape and then ':wq' to write and quit.
The BEGIN and END lines are needed when using a private key. Once the file is saved, change the permissions to 600 or 400. This is required:
chmod 600 deployment_key.txt
Now login using the SSH client. Here’s an example where we’re loading the key in file deployment_key.txt, logging in as the user root, to IP 184.108.40.206:
ssh –i deployment_key.txt –l root <IP>
When asked about if you’re sure you’d like to connect, type yes and hit enter. You will now be logged in as root to this server:
© 2014 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License
See license specifics and DISCLAIMER