Connect Linux Instance with SSH Keys
Learn how to securely connect to Linux instances using SSH keys.
Using passwords for remote Linux access is outdated and risky, leaving systems vulnerable to hacking. The SSH Key based login is the most secure and safest way to connect a remote Linux server. If you have an SSH key, you are connect Linux server!
To remotely connect to Linux servers via SSH keys, two common key file formats are used:
.pem file: Used for connecting remote Linux servers from Mac or another Linux OS
.ppk file: Used for connecting remote Linux servers from Windows using PuTTY
Connect Linux server from Windows using PuTTY
If you have a .pem key file, you cannot use .pem file with PuTTY to connect remote Linux server. You will have to first convert the .pem file into .ppk (Putty Private Key) format and this is done through PuTTYgen software.
Convert PEM to PPK File Using PuTTYgen
Download PuTTYgen software and open it. This software allows you to convert PEM keys to PPK format. Under Actions section, click Load

By default, PuTTYgen displays only files with .ppk extension. To locate your .pem file, select All Files

PuTTYgen displays a notice that the .pem file was successfully imported. Choose OK.
To save the key in .ppk format, choose Save private key. PuTTYgen displays a warning about saving the key without a passphrase. Choose Yes

Open PuTTY and Connect Linux Server with PPK
Open PuTTY and enter the IP address or hostname

On Left hand menu, navigate to Connection > SSH > Auth > Select Credentials. Under Private key file for authentication, click Browse and select the .ppk file
Enable X11 forwarding to invoke Linux GUI, navigate to SSH >> X11 >> Check Enable X11 forwarding
Select Session in the left hand menu, under Saved Session give a meaningful name and click on Save

You can now double click the Saved Session and connect to remote Linux server!
Invoke Linux GUI on Windows using Xming
Download and Install Xming which will allow you to invoke Linux GUI on Windows. Start the installer and Choose Multiple Windows, enter Display number 0, and click Next
Just click Next, Next and Finish the installation. Open PuTTY and enter the IP address
If you have an SSH key, On Left hand menu, navigate to Connection > SSH > Auth > Select Credentials. Under Private key file for authentication, click Browse and select the .ppk file
To enable X11 forwarding, navigate to SSH >> X11 >> Check Enable X11 forwarding
Select Session in the left hand menu, under Saved Session give a meaningful name and click on Save
Double-click the saved session, connect to Linux server and initiate any GUI application like firefox (if installed) or Oracle runInstaller
Transfer files from Windows to Linux using WinSCP
WinSCP allows you to transfer files from your windows system to remote Linux server. Install WinSCP and the default installation option are OK. Start WinSCP, give Host name (or IP Address) and User name of your remote Linux instance
Click Advance button, under SSH and choose Authentication. Specify the path for your .ppk key file, or choose the ... button to browse to the key pair file and Choose OK
Choose Login. To add the host fingerprint to the host cache, choose Yes.
After the connection is established, in the connection window your Linux instance is on the right and your local machine is on the left. You can drag and drop files between the remote file system and your local machine.
Connect Linux server from Windows via OpenSSH
You can use .pem keys on Windows Server 2019 or Windows 10 (build 1809) with PowerShell 5.1 or later to directly connect remote Linux servers. Install OpenSSH on Windows machine to SSH into any remote Linux server:
Open Settings, select System, then select Optional Features
Check if OpenSSH is already installed, else click Add a feature
Find OpenSSH Client and Install
Open cmd and navigate to the folder which contains .pem key
cd downloads
Connect to the remote server using the SSH command
ssh -i <key_name>.pem username@<ip_address>
Type yes and enter the passphrase (if asked) for the SSH key. Enjoy!
Connect Linux server from Mac
You can connect remote Linux servers via Mac using .pem key files. Download the .pem key file, open Terminal app, navigate to Downloads folder and set permissions for the PEM file
cd ~/Downloads
chmod 600 <key_name>.pem
Connect to the remote server using the SSH command
ssh -i <key_name>.pem cloud-user@<ip_address>
Type yes and enter the passphrase (if asked) for the SSH key. Enjoy!
Invoke Linux GUI on Mac
Download and install XQuartz package which will invoke Linux GUI on Mac. Start XQuartz, open terminal and connect to your Linux instance using SSH with -Y parameter
ssh -i <key_name>.pem -Y cloud-user@<ip_address>
Share SSH Key with other user
The cloud servers are generally configured to allow a specific super user like root or cloud-user to connect using SSH key. If you would like to connect to a different user example oracle to invoke GUI, then you will have to share the SSH key with oracle user.
If you are connecting to cloud server with a super user apart from root, like cloud-user then you can simply switch to root user with sudo su -
Connect to the cloud server with super user root or cloud-user and open authorized_keys file
cat .ssh/authorized_keys
Copy the keys that you would like to share with oracle user
Switch to oracle user
su - oracle
Open the authorized_keys file and paste the keys
vi ~/.ssh/authorized_keys
If the authorized_keys file or .ssh folder does not exists then
mkdir -m 700 -p ~/.ssh
vi ~/.ssh/authorized_keys
Paste the keys, save and give 600 permissions
chmod 600 ~/.ssh/authorized_keys
Now you can login to the server with Oracle user and same SSH Key.