These days if you are serious about your web application, You must know how important it is to have it on a cloud server particularly on one of the top service providers like Amazon, Rackspace or Google. But the problem starts when you need to access the machine which is provided to you & you never have heard technical terms like instance, ami & ssh. Many companies provide tutorials but normally they are too damn boring to learn anything. So people try to help each other by providing helpful tips. Today, I will try to help you with 1 thing, which is “how to connect to a remote linux machine using SSH”
So, the first thing I should clear is what I am using for this tutorial. I will show you how to connect to an Amazon AWS EC2 instance from Windows using Putty. If you have a Unix based machine(Like Mac, Ubuntu or Redhat), You will not need need putty or PuTTYgen. You will be able to use the PEM file & the Terminal is good enough for connection. To download putty, Please go to Chiark download page here. You should also download PuTTYgen which is needed to convert your PEM file to PPK file for connection.
Below are the steps to generate a PPK file with PuTTYgen which you will need to make a connection using Putty(You will not need to do any of this if you are using Unix based machine):
Step 1: Load PEM File
Open PuTTYgen and click LOAD to load a private key PEM(Which Amazon provides) file for conversion to PPK(Which PuTTY accepts) file.
TIP: Make sure, You have your PEM file ready which you downloaded from Amazon.
Step 2: Explore & Select PEM File
Locate the .PEM file which you downloaded from Amazon when created a new instance. Amazon may have asked you to check if you have the file. Once you load the file, You should get an alert message saying “Successfully imported foreign key”
TIP: Make sure “All Files” option is selected from File type menu option.
Step 3: Save as PPK file
Type a passphrase which you can easily remember and which is secure enough then click “Save Private Key” to save the key in .PPK format.
TIP: Make sure the Pass key is secure enough but easy to remember as you need to enter it again & again.
Now that you have made sure you have the correct key to be used with Putty in WIndows. We can go ahead & use Putty to connect to a Linux server from Windows. Again, If you are using a Unix based computer, all you need is the Terminal & same steps with Terminal rather than Putty. Please follow below steps for Putty + Windows
Step 1: Create new Session
Open putty and create a new Session. Add host name or IP address of your remote instance. You should find this entry area on 1st page of Putty.
TIP: In case of Amazon AWS, using the instance name is a better idea.
Step 2: Adding User
Go to menu item “Data” from the menu tree on the left. It should be under “Connection”. Add the name of Remote User in the text field called “Auto-login username” which is specific for the Operating System or type of AMI selected. Root is always the Super User for the Linux / Unix servers but for security reasons, that might be disabled by most of the cloud providers. Below are some options for Users for different operating systems:
EC2-User should be the default user of choice for Amazon servers. But if you are using other MIs(Machine Image) rather than Amazon’s own then below are some choices you should try if unable to connect:
- root for SuSe Linux Enterprise
- root for RedHat Linux Enterprise
- ubuntu for Ubuntu Server
Step 3: Adding Private Key for Authentication
Next step is the add your private key for server authentication. In this case you will use the PPK file which we generated earlier with PuTTYgen. In case of Unix/Linux PEM will be the file extension. For this step, You will have to go to “Auth” menu from the menu tree which should be under the menu item “Connection” & then “SSH”. Once on the “Auth” page, simply browse your file.
TIP: No need to fumble around with other options on the “Auth” page. If you want, Do a research about them 1st.
Step 4: Making the Connection
You are all set now to make the connection now with all your settings customized as per requirement. So, go to homepage of & click “Open” to open the connection. Make sure the host is the same which you want to connect to. For first time connection, you will be prompted with an alert, Simple click “Yes”. You should be OK for the connection to be made. Once you are in the CUI mode, you will be asked for the key passphrase which you initially entered while creating your key. That is all!
You are connected & got complete control of server. To make sure you know which files on the location where you landed, Simple type “LS” & hit enter. This should give you a list of all folders and files on this location.
TIP: From here you will need to interact with CUI, So make sure you know few commands.