Following the recommendations in online forums, I have configured my new Ubuntu server so that root can only be accessed via my private key.
My understanding is that I’m also supposed to create a different user account that will be used to handle root-like tasks via elevated privileges and sudo. I can create that account with appropriate privileges, but the server will not allow me to connect via SSH. The only way I can use the other account to access the server is via the Digital Ocean console. The console does not play well with my Mac’s external keyboard.
What do I need to do to enable SSH connections to other accounts? I have found instructions online which suggest changing PermitRootLogin from ‘no’ to ‘yes,’ but that seems to defeat the point of using an encrypted key to control root access. I cannot find instructions which explain how to allow password authentication for everyone EXCEPT the root user.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
You’ll need to create a user and add it to the sudoers group
You’ll start by creating a user called exampleuser using the adduser command while creating the user’s home directory
Once you’ve created the user, I’ll recommend setting a password. To do so execute:
Then use the usermod command to add the user to the sudo group
You can test if everything was done correctly by using the su command
You can also try and open a file somewhere. Maybe you can try and open a file in /etc just to see if you have permission to edit it.
If you don’t see permission denied you are good to go.
There is something I like to point out. If you add your users to the sudoers group, they’ll have the power of a root user.
Now to allow SSH access to a certain user
Update on 10.07.2021 Initially, this answer contained information how to enable a user or a group to SSH however this has been outdated.
As such, I’ve updated the answer to providing information on how to configure your SSH keys on the user.
Now that you have the user-created, SSH to your Droplet using the root user and switch to the newly created one:
Once inside, go to your home folder with the cd command
If you followed the whole answer this will bring you in the /home/exampleuser directory.
Now, you need to create the folder .ssh and an authorized_keys file, you can do it like that:
All that is left to do is copy your SSH key in the authorized_keys file and you are good to go.
Kind regards, KFSys
I just followed your advice, and now I can’t login with my created user nor root… Wtf!? 😢
Want to learn more? Join the DigitalOcean Community!
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Sign up now
Also there is something to do at: /etc/passwd specify the user space for logged user and shell.