Skip to content

Instantly share code, notes, and snippets.

@NicholasBallard
Last active October 21, 2019 18:06
Show Gist options
  • Save NicholasBallard/461081a1d918feba052a04a23d680253 to your computer and use it in GitHub Desktop.
Save NicholasBallard/461081a1d918feba052a04a23d680253 to your computer and use it in GitHub Desktop.

How to Log In to an EC2 Instance Using SSH

Save your key pair downloaded from the EC2 accounts page for the server instance to your local machine.

Save the file in a readily accessible place on your disk. I like saving keys in a directory called keys in my root.

PEMFILE=/path/to/pem/file.pem
mkdir -p /c/keys
mv $PEMFILE /c/keys

Because of an EC2 permissions policy, the key pair file needs to be OpenSSH standard (don't worry about this). What you do need to do, however, is limit the permission on the file to read-only. Use the chmod program on a *NIX system shell for this. If you're using Windows, use Git Bash for Windows or WSL Ubuntu or openSUSE.

chmod 400 /c/keys/$PEMFILE

On my machine the command looks like this:

cd "C:\\keys"
chmod 400 redshift2gsheets.pem

Now it's time to log in to the EC2 server!

In this example we are going to use a server running some programs for Ruggable. Best practice is to create a different user for each... well, user. But! We're in a trusting mood, so the Ruggable techie is going to log in to the ubuntu user on the EC2 instance.

On Windows you can use PuTTY. But don't. Everyone should be logging in from a Bash-like shell. The command line is your friend. You can later use the alias command to log in using just a few keystrokes. On my machine, I set an alias where typing rvm logs in to this Ruggable VM. Handy when you are working with multiple remote servers.

Log in using the ssh program.

ssh -i /c/keys/redshift2gsheets.pem [email protected]

Accept the prompt by typing yes... and you are in!

Successful Login

💾💾💾

Still need help? Contact me!

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