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:
- First Create a ec2 instance on aws portal so click on link https://www.hackerxone.com/blog/how-create-ec2-instance-amazon-web-serviceaws for how to create ec2 instance on aws account.
- Login to ec2 instance using public key & DNS of ec2 instance with sudo privileges.
- Now create a user with a specified home directory.Mention the name of user in place of newuser.
useradd -m -d /home/newuser -s /bin/bash newuser
- 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).
- 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
• Now provide the follwoing permissions.
chmod 600 .ssh/authorized_keys
chown newuser:newuser -R .ssh
chmod 0700 .ssh
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
- Open the sshd_config file.
vim /etc/ssh/sshd_config
- Search & Enable the PasswordAuthentication(Public Key authentication).By default, PasswordAuthentication is disable.
PasswordAuthentication yes
- Then restart the ssh.service .
systemctl restart ssh.service