This post will walk you through steps of creating a new non root user and configure sudo privileges with it. This post not just focuses on DigitalOcean Droplet but rather can be used for any linux based system.
Well, so you've spin up your Digital Ocean droplet and configured it with your SSH and have a root user to login from your terminal or bash.
But it is not a good option to use the root user, as the root user has the maximum level of access and rights, which might accidentally cause some problem. So a better choice is to create a new user.
Let's follow through the steps to create a new user and assign sudo privileges to it.
-
Login to your droplet using terminal or bash or PuTTY(Windows).
ssh root@<ip-address-of-your-droplet>
-
Create a new user,
<new-user>
(Replace<new-user>
with your desired username).
adduser <new-user>
-
Congratulations, π . You've created a new user. You can verify it using,
id <new-user>
-
Let us add the
<new-user>
to the sudo group to get the sudo privileges.
usermod -aG sudo <new-user>
-
Now let us add SSH key for the new user so that next time we can connect to droplet using
<new-user>
using SSH. Switch the user from root to using,
su - <new-user>
-
Create a directory .ssh into home dir. Change permissions for that dir. Follow the commands,
sudo mkdir ~/.ssh sudo chmod 700 ~/.ssh
-
Create a file named authorized_keys and paste your SSH key in there. Also change the permission for it.
sudo vim ~/.ssh/authorized_keys Paste the key and save the file. sudo chmod 600 ~/.ssh/authorized_keys
Note
: If you want to know how to generate SSH keys follow this doc from Git here.
Congratulations, π . You've successfully created a non-root <new-user>
with sudo privileges to work with. You can now login your droplet using,
```bash
ssh <new-user>@<ip-address-of-your-droplet>
```
Thanks for reading through.
Comment down if you have any doubts.
Like if you find this post useful. I welcome your opinions and constructive criticism. You can find me on twitter or my website.
Cheers!
Top comments (0)