How do I enable passwordless ssh login and give sudo rights to a user?

Situation

You want to enable a user to login to your virtual host without giving a password. Additionaly, the user should be able to act with root permissions on the server.

Resolution

new_user
the username you want to give access and sudo permissions
new_user_group
the groupname of the new user

Generate a keypair for the new user

ssh-keygen -b 4096 -t rsa -N '' -f new_user

Bemerkung

If you must generate the Public-Private KeyPair using putty on Windows, you can convert the putty-public-key to the openSSH Format using the following command:

ssh-keygen -i -f new_user.pub > openssh_new_user.pub

Enable ssh-KeyPair access

Log into your virtual server as root and use the fowlloing command sequence:

cat your_public_key.pub >> /home/new_user/.ssh/authorized_keys
chown new_user:new_user_group /home/new_user/.ssh/authorized_keys
chmod 0600 authorized_keys

Note: If there is no directory /home/new_user/.ssh you have to create one and set the right permissions on it:

mkdir /home/new_user/.ssh
chmod 0700 /home/new_user/.ssh

Enable sudo access for the new user

Log into your virtual server as root and use the fowlloing command sequence:

cat 'new_user ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/new_user