How to ssh to a Linux-based AWS EC2 instance - issue with having to execute command from within .ssh directory

Viewed 21

Experience Level: Novice to AWS, some slight experience with Linux/Unix

Current Setup

  • I'm using a Macbook Pro 2021 laptop running OS Monterey and using the standard Apple terminal.

  • I have created two Linux EC2 instances in AWS, one Ubuntu and one RedHat8 with all the necessary options.

  • The connect information from AWS is sudo ssh -v -i <"name of .pem file" ubuntu@ec2ipaddress.compute-N.amazonaws.com.

  • I have my .pem file located in my .ssh directory.

Current Blocker

  • To ssh into either EC2 instance, I must cd into .ssh and run the command from within the directory.

  • I want to be able to ssh without having to do it from the .ssh directory. This issue occurs for both the Ubuntu and Red Hat instances.

Secondary issue

Trying to set an environment variable is a "twisty little path" as the Mac has .bashrc and zshrc with no dot. Then there is the zshrc_profile, knownhosts, zshrc_Apple Terminal and the equivalent . versions.

When I attempt to use PATH= even as root, I get a message that states there is no .ssh directory. So I can't seem to reference the .pem file.

Options

Is this an Environment Variable issue? If so what is the easiest way to set the variable so I can execute the ssh command outside the .ssh directory?

Is there some other workaround?

0 Answers
Related