loading...
Cover image for Microblog - Create a new non-root user with sudo privileges on Ubuntu based DigitalOcean Droplet configured with SSH

Microblog - Create a new non-root user with sudo privileges on Ubuntu based DigitalOcean Droplet configured with SSH

mistryvatsal profile image Vatsal Mistry ・2 min read

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.

  1. Login to your droplet using terminal or bash or PuTTY(Windows).

    ssh root@<ip-address-of-your-droplet>
    
  2. Create a new user, <new-user> (Replace <new-user> with your desired username).

    adduser <new-user>
    
  3. Congratulations, 😃 . You've created a new user. You can verify it using,

    id <new-user>
    
  4. Let us add the <new-user> to the sudo group to get the sudo privileges.

    usermod -aG sudo <new-user>
    
  5. 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>
    
  6. Create a directory .ssh into home dir. Change permissions for that dir. Follow the commands,

    sudo mkdir ~/.ssh
    sudo chmod 700 ~/.ssh
    
  7. 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!

Posted on by:

mistryvatsal profile

Vatsal Mistry

@mistryvatsal

Application Developer. Converting caffeine into code.

Discussion

markdown guide