add user and create ssh folder and add ssh key to authorized_keys centos

First we need to create the user before we create the ssh folder and the file authorized_keys

Step one user creation

Add user:

sudo useradd theusername

add user to the wheel group  ( -a = append G is group wheel is the group to add the user to! )

sudo usermod -aG wheel theusername

Set password for user theusername

sudo passwd theusername

Test the sudo for the user theusername

sudo ls -la /root

Step two create the .ssh folder and authorized_keys and set permissions

create .ssh folder

mkdir ~/.ssh

cretate the file authorized_keys

touch authorized_keys

change permissions on ssh folder

chmod 700 ~/.ssh

change permission on file authorized_keys

chmod 600 ~/.ssh/authorized_keys

restore SELinux settings on ~/.ssh

restorecon -Rv ~/.ssh

Step three copy the ssh_key to server

open ~/.ssh/authorized_keys and add your public key

vi ~/.ssh/authorized_keys

I am a Senior System Administrator that work daily with Virtualization,Xenserver, Linux, IT automation, Ansible,Windows, Active Directory, Exchange and a lot more. Here you will find tips and trix from early junior, middle junior and senior to unique information of the topics I mentioned earlier. If you need help with something do not hesitate to contact me I will gladly help.

Tagged with: , , , , ,