Connect over ssh using a .pem file

SshPem

Ssh Problem Overview


I would like to know how to connect over ssh using a .pem file to any server.

Currently I'm executing the following command:

ssh user@mydomain.com

What option should I use?

Ssh Solutions


Solution 1 - Ssh

Use the -i option:

ssh -i mykey.pem user@mydomain.com

As noted in this answer, this file needs to have correct permissions set. The ssh man page says:

> ssh will simply ignore a private key file if it is accessible by others.

You can change the permissions with this command:

chmod go= mykey.pem

That is, set permissions for group and others equal to the empty list of permissions.

Solution 2 - Ssh

chmod 400 mykey.pem

ssh -i mykey.pem user@mydomain.com

Will connect you over ssh using a .pem file to any server.

Solution 3 - Ssh

For AWS if the user is ubuntu use the following to connect to remote server.

chmod 400 mykey.pem

ssh -i mykey.pem ubuntu@your-ip

Solution 4 - Ssh

To connect from Terminal to AWS AMI:

chmod 400 mykey.pem

ssh -i mykey.pem ec2-user@mydomain.com

Solution 5 - Ssh

You can connect to a AWS ec-2 instance using the following commands.

chmod 400 mykey.pem

ssh -i mykey.pem username@your-ip

by default the machine name usually be like ubuntu since usually ubuntu machine is used as a server so the following command will work in that case.

ssh -i mykey.pem ubuntu@your-ip

Solution 6 - Ssh

If you still got error messages like:

> Received disconnect from 34.219.50.0 port 22:2: Too many authentication failures. Disconnected from 34.219.50.0 port 22

  1. Edit your ssh config located at ~/.ssh/config and add new record at the end
Host mydomain.com
   User ubuntu
   IdentityFile /home/you/path-to-pem/key.pem
   IdentitiesOnly yes  
  1. Call short command: ssh mydomain.com

Solution 7 - Ssh

what resolved it for me was to run: sudo chown $USER: {.pem_file}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondanielrvtView Question on Stackoverflow
Solution 1 - SshlegosciaView Answer on Stackoverflow
Solution 2 - Sshshubham rajputView Answer on Stackoverflow
Solution 3 - SshPranoy GnView Answer on Stackoverflow
Solution 4 - SshshbedevView Answer on Stackoverflow
Solution 5 - SshofficialrahulmandalView Answer on Stackoverflow
Solution 6 - SshpymenView Answer on Stackoverflow
Solution 7 - SshDevqxzView Answer on Stackoverflow