How to Create SSH user with & without key on AWS EC2 instance.

SSH (Secure Shell) is a network protocol that enables secure remote connections between two systems. System admins use SSH utilities to manage machines, copy, or move files between systems. Because SSH transmits data over encrypted channels, security is at a high level.

We can create SSH user with Key & without key.

SSH User with Key:

             useradd -m -d /home/newuser -s /bin/bash newuser

 

Fig 1

 

  • Go to newuser directory.

   cd /home/newuser

  • Create a ssh key.

   ssh-keygen

Then set the path of ssh key where key wiil create like /home/newuser/example & Press Enter.(Provide the key name in place of example).

Fig 2

 

  • Change the name of example instead of example.pk

     mv example example.pk

  • Make a folder with name .ssh .

     mkdir .ssh

  •  Move the content of example.pub to .ssh/authorized_keys.

     cat example.pub >> .ssh/authorized_keys

Fig. 3

 

• Now provide the follwoing permissions.

   chmod 600 .ssh/authorized_keys

  chown newuser:newuser -R .ssh

  chmod 0700 .ssh

Fig. 4

 

SSH user without Key:

  • Login to ec2 instance with sudo privilege.
  • Now create a newuser.Mention the name of user in place of user-name.

          useradd user-name

  • Set the password.

         passwd user-name 

 

Fig. 6

 

  • Open the sshd_config file.

   vim /etc/ssh/sshd_config

  • Search & Enable the PasswordAuthentication(Public Key authentication).By default, PasswordAuthentication is disable.

          PasswordAuthentication yes

 

Fig. 7

 

  • Then restart the ssh.service .

          systemctl restart ssh.service

 

Leave a Reply

Your email address will not be published.