This content originally appeared on Level Up Coding - Medium and was authored by Meta Collective
These methods will work for most of the Linux based servers, but for this tutorial, I will explain it in context with AWS

What is SSH?
The Secure Shell Protocol (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution.
SSH applications are based on a client–server architecture, connecting an SSH client instance with an SSH server. SSH operates as a layered protocol suite comprising three principal hierarchical components: the transport layer provides server authentication, confidentiality, and integrity; the user authentication protocol validates the user to the server; and the connection protocol multiplexes the encrypted tunnel into multiple logical communication channels.
From wiki
In plain English, it is a protocol (just like HTTP for transmitting hypermedia documents) using which you can communicate securely with a server.
On AWS, when you add a new ec2 instance it is added to a VPC (virtual private cloud), and anyone outside that VPC trying to access that machine (and sometimes within that VPC) will need a private key. It has a .pem extension. For you to get connected, you must have that private key with you. If you don’t have it, then ask your system administrator/DevOps or whoever is responsible for managing these machines/instances on AWS.
Prerequisites
- Access to the private key
- Public DNS or IP of the machine on AWS
- Port 22 is open on the ec2 instance. Please check in the security group assigned to this instance.
- Some kind of FTP client (FileZilla, CyberDuck, etc.) for options 2 & 3
Once you have that private key, make sure that your key is not publicly viewable. You can ensure that by running this command in your terminal
There are usually two ways in which an ec2 instance is exposed to the general public network.
The first one is direct access via a private key over ssh protocol

To connect to an ec2 instance with this setup is very straightforward.
Option 1, using a terminal
Simply run this command in your terminal (replace it with your own value)
Once you are connected your terminal will have access to the ec2 instance.
Option 2, using a sftp client
I am going to use FileZilla as an example, but it will work with any other client as well
- Open your FileZilla client and add a new site like this

- Change protocol to ssh like this

- Add public DNS or IP address of the ec2 instance in the host field
- Select Key file as logon type like this

That’s it, now simply click on connect button and you will have access to the ec2 instance.
The second one is via a jump server(also known as a bastion box, jump box, jump host, etc.) where the ec2 instance is set up inside a private subnet of the VPC with very limited access to the outside world and only accessible via another server in the public subnet of the VPC.

Option 1, using a terminal
- Add your user key for the jump box to your SSH agent
- Add the key for the protected server to your SSH agent
- Start jumping 😆
Option 2, using a sftp client
- Connect to the server using the ssh like this
- Now, head over to FileZilla and open settings, and go to ‘Generic Proxy’ like this

- Then select SOCKS 5 as generic proxy and enter value 8001 in the proxy port field
- Then add a new site as we did earlier and do the following
- Select SFTP as protocol
- Add the private IP/DNS of your protected server
- Select ‘Key File’ as the logon type
- Add private key of the protected ec2 instance - Click connect and you are now connected to your ec2 instance sitting behind a jump server.
4 ways to SSH on an EC2 instance was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Meta Collective

Meta Collective | Sciencx (2022-02-27T20:19:19+00:00) 4 ways to SSH on an EC2 instance. Retrieved from https://www.scien.cx/2022/02/27/4-ways-to-ssh-on-an-ec2-instance/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.