3 C
New York
Sunday, January 17, 2021

Buy now

Connect Amazon EC2 and GCP Instance without pem or SSH keys

Amazon EC2 and Google Cloud instances by default do not allow to login without .pem key (for AWS EC2 Instance) and SSH key (for Google Cloud Instance) for your instance security.

Connect Amazon EC2 and GCP Instance without pem or SSH keys

The tutorial will help you understand, how to connect your Amazon EC2 instance without .pem key and how to connect Google Cloud Instance without SSH keys as you may be in a situation (at a remote location) or on someone else’s computer/laptop, you want to access your instance and you don’t have ssh keys or the .pem keys because you can’t carry those with you so it becomes pain in the ass. You will learn how to connect your instances with password.

For the security point of view, it’s more secure to access your instances with ssh keys/.pem keys as those resides on your computer and secure. Accessing your instances with password is not recommended per my understanding and advice as it is less secure but for such situation you are on someone else’s PC or on a remote location and you want to connect your instances with password.

Note: Once you learn ssh access from anywhere, you might be interested to Install and Configure CyberPanel on CentOS 7

Let’s implement a solution so you login to your instance with a password. Again, this is less secure than using SSH/.pem keys so it is very important to create a very strong password.

1. Spin up an instance on AWS/GCP

2. Connect your instance using SSH/.pem Key file

Example for connecting Amazon EC2 instance:

ssh [email protected] -i file_name.pem

Example for Google Cloud instance:

ssh [email protected]

3. Create a strong password for the user:

sudo passwd ubuntu

Enter new UNIX password:

Retype new UNIX password:

4. Enabling password authentication so you can access your instance with password:

sudo vi /etc/ssh/sshd_config

5. change the followoing two parameters:

PermitRootLogin no to PermitRootLogin yes

PasswordAuthentication no to PasswordAuthentication yes

6. Restart ssh service so the settings we made can take affect

sudo service sshd restart

7. Logout of your instance (exit) and try to connect your instance without the SSH/.pem keys

Example for connecting Amazon EC2 instance:

ssh [email protected]

[email protected]’s password:

Example for Google Cloud instance:

ssh [email protected]

[email protected]’s password:

How to create New User and how to make it sudo/root

If you intend to create and use own username instad of root/ubuntu. Following are the step you can follow to create your new user and grant access to do sudo actions:

1. By execuing following command, it will create a new user that will be used to access the instance using a password

Remmeber to change USERNAME with your desired login name i.e alizia or iamroot etc. etc.

sudo useradd -s /bin/bash -m -d /home/USERNAME  -g root USERNAME

for example, i am going to create a user alizia so i am replacing USERNAME to alizia in the following command.

sudo useradd -s /bin/bash -m -d /home/alizia  -g root alizia

Here are the explanations of the switches used in the about command so you can have understanding of the full command you have executed:

-s /bin/bash : This switch will grant /bin/bash to your username as the standard shell

-m -d /home/USERNAME : This switch will create a home directory at /home/USERNAME for you

-g root : This switch will add you to root group

USERNAME : This is the username of the new user i.e alizia or iamroot

2. Create a strong password for the new user:

sudo passwd USERNAME

Enter new UNIX password:

Retype new UNIX password:

3. Add user to sudoers file to grant sudo access:

sudo visudo

now add your username and set permissions


and restarte sshd service:

sudo service sshd restart

4. Try to connect your instance with your new username and password.

ssh [email protected]


ssh [email protected]


The tutorial has well briefed the importance of SSH when you are not on your PC or on a remote machine but still want to access your node. We hope that you would love video demonstration walk-through which has been recorded for your better understanding. So after seeing reading this tutorial or watching the tutorial video, you will be able to ssh your node from anywhere.

Youtube Channel: https://www.youtube.com/channel/UCBxPI_6j82UA7ahUhV5owvQ/

Related Articles

Stay Connected

- Advertisement -

Latest Articles

%d bloggers like this: