DEV Community

loading...

Access EC2 without pem file with with username and password

boobo94 profile image Bogdan Alexandru Militaru Originally published at boobo94.github.io on ・1 min read

Sometimes you need to grant permissions to someone else and maybe you don’t want to share the .pem file. By default, the ssh access is granted through a .pem file by Amazon EC2.

  1. You can create your own user and access the server using a password. In order to set up this, firstly first let’s login on the server as usual
$ ssh -i pem_file.pem ubuntu@ec2- ________.compute-1.amazonaws.com
Enter fullscreen mode Exit fullscreen mode
  1. Create a new user
$ sudo useradd -s /bin/bash -m -d /home/USERNAME -g root USERNAME
Enter fullscreen mode Exit fullscreen mode
  1. Add a password
$ sudo passwd USERNAME
Enter fullscreen mode Exit fullscreen mode
  1. Add users to sudoers
$ sudo visudo
Enter fullscreen mode Exit fullscreen mode

Here you need to add the following line

USERNAME ALL=(ALL:ALL) ALL
Enter fullscreen mode Exit fullscreen mode
  1. Enable the access by password through ssh
$ vi /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode

Here you need to search PasswordAuthentication from no to yes.

  1. Restart ssh
$ sudo /etc/init.d/ssh restart
Enter fullscreen mode Exit fullscreen mode
  1. Connect to the server using the new user
$ ssh USERNAME@ec2- ________.compute-1.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

This is all.

If you consider this tutorial was useful please let me a comment or share the article. For any suggestions or comments, please drop me a line below.

The post Access EC2 without pem file with with username and password appeared first on boobo94.

Discussion (0)

pic
Editor guide