All HowTo's Cybersecurity Linux

Creating New Users & Placing SSH Keys on Ubuntu and CentOS/Redhat

This is a simple reminder to those creating user accounts on Linux systems with the expectation that the intended user will be able to log in using their SSH keys. There’s also instructions on adding them to the “sudoers” groups.

Ubuntu & CentOS/Redhat

Create the user and place their SSH public key for them:

useradd -m <username>
mkdir /home/<username>/.ssh
vi /home/<username>/.ssh/authorized_keys #add the key
chown <username>.<username>-R /home/<username>/.ssh 
chmod 700 /home/<username>/.ssh
chmod 600 /home/<username>/.ssh/authorized_keys

If you want that user to be able to SUDO, consider these additional steps:

Ubuntu

# If “/etc/sudoers” doesn’t have “%sudo ALL=(ALL) NOPASSWD: ALL” set

passwd <username>

# Add the user to the “sudo” group

usermod -aG sudo <username>

CentOS/Redhat

# If “/etc/sudoers” doesn’t have “%wheel ALL=(ALL) NOPASSWD: ALL” set

passwd <username>

# Add the user to the “wheel” group

usermod -aG wheel <username>

Leave a Reply

Your email address will not be published. Required fields are marked *