Mac SSH Amazon Using Pem

💡 This post is insightful for the following scenarios.

  • Use .pem file to ssh

Background

The title has said enough

Step

1. Put .pem file in folder XXX

2. Open terminal in folder XXX

3. Run SSH command to connect

1
ssh -i "key.pem" username@ipaddress

4. Permission error (probably)

What you need to do is to set up a suitable file permission (0600).

1
chmod 0600 key.pem

Then run the command given in step 3. And this time there is no error message.

5. If you want to add .pem file into your system…

1
2
3
4
ssh-add -K key.pem
ssh username@ipaddress

# however, in this way you need to do it again when you turn off your machine

So, are there any ways that can elegantly solve this problem all at once?

Sure! Check here!