Configure SSH authentication for users

When you create a Linux VM/EC2 instance on cloud, you get a choice to either create a user ID password or use SSH authentication.

While creating the VM its is quite straight forward. You take the “Public Key phrase” from the key generator and paste it in the space provided. You will be allowed to login with this key.

Below steps help you in adding additional users to the VM once created.

Login to the Linux machine with root privileges.

Obtain the public key file (generated via Puttygen or ssh-keygen) from the end user and copy it on the server where it has to be added.

Create the required user using below command. There is no dependency between user name and the key files.

[root@testsshserver]# useradd -m <user_name> -s /bin/bash

Create the directory path required for SSH keys

[root@testsshserver]# cd /home/<user_name>/

[root@testsshserver]# mkdir .ssh

[root@testsshserver]# cd .ssh

[root@testsshserver]# chmod 700 .ssh

[root@testsshserver]# cd .ssh

Create the key file

[root@testsshserver]# touch authorized_keys

[root@testsshserver]# chmod 644 authorized_keys

Copy the public key file content into the “authorized_keys file”

[root@testsshserver]# cat <path to public file>/<pubilc key file> >> authorized_keys

[root@testsshserver]# chown <username> authorized_keys

Edit the file to have the correct format. Normally when you generate the file from puttygen, the content starts with “—- BEGIN SSH2 “.

Make sure adjust the content to look like below:

ssh-rsa AAAAB3fafsdal;fasd;lkjfasd;lkjfadslkjfadskjfsdkjlfdaskjsfdkjldsfakjdfffffkfdkdbgJscZiA

Now you should be able to ssh to the server using the private key file and the passphrase if used.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s