How to SSH into a Linux EC2 Instance and its Benefits
Today we are going to do a quick demostration of how to Secure Shell (SSH) protocol into an EC2 instance and it’s benefits. To showcase our SSH and it’s benefits we will use the following business as an example.
Level Up Corporation, a mid-sized tech company, leverages the power of Amazon Web Services (AWS) Elastic Compute Cloud (EC2) to host both its Linux and Windows applications. The company currently has 100+ EC2 instances running simultaneously. Level Up has a dedicated IT team located globally to handle the administration and maintenance of these instances. However, due to the absence of a reliable, secure, and direct remote administration tool, the IT team faces significant challenges in efficiently managing, troubleshooting, and maintaining these servers, leading to prolonged downtime, decreased productivity, and potential security risks
Let’s now demostrate how to SSH into an EC2 then disscuss how this would benefit Level Up Corporation’s current issues.
Prerequisites
- AWS Command Line Interface (CLI) install on device
Step One- Create a Key Pair and Launch an EC2 Instance
First we will type EC2 in our AWS console and select the first option. After selecting EC2 we will create a Keypair. We will need this in order to securely access our EC2 instance anywhere globally. To do so on the right hand side of the console select Key Pair and follow along in the video below:
After making our key pair a .pem file will download. It is critical that we save this file and have access to it as this is our private key we will use to SSH into our EC2 Instance. Once we have saved our file to a folder we can access easily we will now go and launch our EC2 intance as shown here.
Now that our EC2 instance is created we will need to copy the public IPv4 address which can be found by selecting our EC2 instance
Step Two- SSH using our Command Shell
Now that we have our public IP address and our Private Key we will launch our computer’s command shell. For any Mac device you can use Terminal and for a Windows Device you can use the Command Prompt. For myself I use a Macbook, but instructions for Windows can be found here.
Let’s get started. First we will open our Command Shell and go to the directory where our .pem file is saved. To do so type
clear
Then you will type
ls
This will bring up a list of directories on your machine. You will thing have to type in the name of path where your .pem file was saved. For me I saved it in a folder on my desktop call DemoSSH. So next I would type in the following commands in order to access my key.
cd Desktop
Press enter then type
ls
This will bring up all the files under the requested directory. Next we will type the name of where my .pem file is saved on Desktop which was DemoSSH so I’ll type
cd DemoSSH
I should have a screen that now looks like this
From here we will now type in the following command
ssh -i /path/key-pair-name.pem ec2-user@publicIPaddress
After the @ should be the Public IPv4 address we copied earlier. We will press enter. It should bring up a screen that looks something like this:
We will type in yes and we should be able to SSH into our EC2 instance. However we might be greeted to a screen that looks something like this
This is because our key pair is saved on a pubilcly accessible location on our machine. To get around this screen we will type:
chmod 400 key-pair-name.pem
Then press enter to get to a screen that will looks as such
This screen means we have successfully SSH into our EC2 instance. To confirm we can type
whoami
Into the command line and we should get the result ec2-user
Conclusion and Benefits
So what benefits will Level Up Corporation recieve from doing the above method of accessing their EC2 instances? Here are a few:
- Improved Productivity and Efficiency: SSH provides direct access to EC2 instances. This enables the IT team to promptly respond to server issues, reducing downtime and improving overall operational efficiency.
- Enhanced Security: SSH provide secure, encrypted channels for communication. This helps to prevent unauthorized access and data breaches, maintaining the integrity and confidentiality of the company’s data.
- Cost Savings: By reducing server downtime and enhancing IT team efficiency, the company can decrease operational costs. In addition, a fast response to issues can prevent potential financial losses associated with severe server malfunctions or security breaches.
- Easy Administration and Troubleshooting: SSH enables the execution of commands and access to server resources, simplifying server management, configuration, and troubleshooting. This allows the IT team to provide better support and maintenance.
- Scalability: As Level Up expands and the number of EC2 instances increases, having a robust, secure remote access tool is crucial for managing a larger server infrastructure.
By implementing this, Level Up Corporation can ensure secure, efficient, and reliable remote administration of their EC2 instances, thereby enhancing business operations and reducing potential risks.
Okay I hope this was a useful demostration. Next time in a future post we will show how to do the same thing for a Windows EC2 instance using Remote Desktop Protocol (RDP)