Initial Ubuntu Server Setup: Root, Users, and Sudo Troubleshooting

I still remember the first time I rented a VPS.
I logged in as root, typed a few commands I found in a tutorial, then suddenly…
sudo: command not found and later user is not in the sudoers file.

I thought I broke the server.

If that sounds familiar, this article is for you.

This is a practical, step-by-step walkthrough of an initial Ubuntu server setup flow based on that classic “Initial Server Setup with Ubuntu 12.04” style tutorial, plus the real problems people hit in the comments:

  • You created a user… but sudo is “not allowed”
  • visudo says Permission denied
  • New user login gives connection refused

I’ll walk you through what’s going on and what to check, slowly and safely.

Who This Is For (And What We’re Fixing)

This guide is for you if:

  • You’re a new VPS user (maybe your first server)
  • You logged in as root, made a new user, and tried to give it sudo
  • But when you switch to that user and run sudo, you get errors like:
  • not allowed to run sudo
  • user is not in the sudoers file
  • visudo: /etc/sudoers: Permission denied
  • Or your SSH login as the new user says connection refused

We’ll go over the usual flow of that initial Ubuntu setup:

  1. Log in as root
  2. Change root password
  3. Create a new user
  4. Give that user root/sudo privileges safely using visudo
  5. Test the new user connection and fix common errors

I’ll focus on the logic and troubleshooting, not fancy extras.

Step 1 – Log In as Root and Change the Root Password

Most basic VPS setups still drop you in as root the first time.

If you’re new, remember: root can do anything.
A typo as root can delete your whole system.
So we want to use root only for initial setup, then switch to a normal user with sudo.

Typical first login is something like:

ssh root@your_server_ip

Once you’re in, change the root password to something strong and unique:

passwd

Why this matters: If someone guesses or steals your root password, your server is gone.
This is the first simple layer of safety.

Step 2 – Create a New User Account

After securing root, the usual tutorial flow is to create a non-root user.
This user will be your daily driver.

From the root shell:

adduser newuser

You’ll be asked for a password and some optional info (you can skip most of it).

Safety tip:
– Use a different password from root
– Don’t reuse your email or social media passwords

Once created, you should be able to switch to that user with:

su - newuser

If that works, the account exists and can log in locally.
We still need to give it sudo powers.

Step 3 – Give the New User Sudo Access via visudo

This is where many people get stuck.
You follow a tutorial, add your user to sudoers, then… sudo still doesn’t work.

The correct and safe way to edit the sudo configuration is:

visudo

Why visudo?

From the tutorial’s own explanation in the source: the visudo command:

  • Locks the sudoers file against multiple edits
  • Does basic sanity checks
  • Checks for parse errors

In plain language: it helps prevent you from breaking sudo completely.

When visudo opens /etc/sudoers, the common pattern tutorials suggest is to add something like this line (example format):

newuser ALL=(ALL:ALL) ALL

The exact syntax may vary by tutorial, but the idea is:

  • newuser – your username
  • ALL=(ALL:ALL) ALL – can run all commands as any user using sudo

Save and exit.

Important: make sure you did this step as root, not as the new user (yet).

Step 4 – Test Sudo as the New User (and Fix “Not Allowed” Errors)

Now log out from root and log in as the new user.
Either via SSH:

ssh newuser@your_server_ip

or locally from a root shell:

su - newuser

Then test sudo with something harmless:

sudo whoami

If everything is correct, you should see:

root

But if you’re here, you probably see something like:

  • newuser is not allowed to run sudo on this server
  • or you can’t use sudo at all

Based on the problems mentioned in the original comments, here are the usual causes and how to think about them:

  1. The user wasn’t actually added to sudoers
  2. Double-check: did you really save the change in visudo as root?

  3. The sudoers file edit failed sanity checks

  4. If visudo detected an error, it may have refused to save changes.

  5. You’re trying to run visudo as the new user before it has sudo

  6. This leads to Permission denied errors (we’ll handle this next).

At this point, if sudo does not work for the new user, go back to root and re-check your sudoers file.

Step 5 – Fixing “visudo: /etc/sudoers: Permission denied”

One specific comment from the source was:

hi, after login as root and update visudo for a newuser, i logout root, login with newuser do visudo command again but visudo say: /etc/sudoers: Permission denied any idea what newuser doesn’t have the root permision??

There’s a key detail hidden there:

  • visudo edits /etc/sudoers
  • /etc/sudoers is owned by root
  • Only root (or a user allowed to use sudo) can edit it

So if you:

  1. Edit sudoers as root
  2. Log out
  3. Log in as the new user
  4. Try to run visudo without sudo

You’ll get:

/etc/sudoers: Permission denied

That does not automatically mean the user doesn’t have sudo.
It just means you tried to edit a root-owned file as a regular user.

To test properly:

  1. Log in as newuser
  2. Run:

bash
sudo whoami

  1. If sudo is working, then:

bash
sudo visudo

If sudo itself fails (before visudo), then yes, the user does not have sudo privileges yet.
In that case, follow this recovery path:

  1. SSH back in as root
    bash
    ssh root@your_server_ip

  2. Run visudo again as root
    bash
    visudo

  3. Carefully verify the line you added for newuser is present and correctly formatted

  4. Save and exit, then re-test with newuser

Key idea: you never run plain visudo as a normal user.
You either:

  • run visudo as root, or
  • run sudo visudo as a user that already has sudo.

Step 6 – Handling “After Setting Root Privileges I Still Can’t Run sudo”

Another complaint in the source was basically:

After setting root privileges to my user I still can’t run sudo (not allowed)

When that happens, here’s a simple mental checklist you can walk through.
You don’t need deep Linux knowledge, just go step by step.

  1. Confirm the user exists
    As root:
    bash
    id newuser

    If it says no such user, your adduser step failed.

  2. Confirm your sudoers change is really saved
    As root, open via:
    bash
    visudo

    Scroll and check: is there actually a line for newuser giving permissions?

  3. Make sure you didn’t create a typo in the username
    newuser vs newUser vs new_usersudoers is strict.

  4. Test a basic sudo command as the user
    bash
    sudo -l

    This lists allowed commands. If even this fails, sudo isn’t wired up yet.

If all that matches what your tutorial told you to do but it still doesn’t work, go back to root and carefully reapply the instructions exactly.

Step 7 – Fixing “Connection Refused” When Logging in as the New User

Another user in the source said this:

After following the steps, I’m in the final step of checking if I can connect with the newly created user but I’m getting an error saying “connection refused”.

Important detail: connection refused usually means SSH itself is not accepting the connection at all, not a wrong password.

In the context of following a basic initial setup tutorial, the most common simple explanations are:

  • You’re trying to connect with the wrong username or port, and the SSH service isn’t listening where you expect
  • The SSH service is not reachable from your network (firewall, network issue)

But staying strictly within the source context, here’s how to reason about it at a beginner level:

  1. Check that logging in as root still works
    If ssh root@your_server_ip also gets connection refused, then the problem is not the new user; it’s the SSH connection itself.

  2. If root login works but newuser fails

  3. You might actually be getting a different error (like Permission denied (publickey,password)), not connection refused
  4. Double-check the actual error text; tiny differences matter

  5. Confirm the username
    Make sure you are using:
    bash
    ssh newuser@your_server_ip

    and not still trying with root@.

If you get true connection refused only intermittently, it’s often network or provider-side.
If it happens only for the new user, re-check the exact error message carefully.

Step 8 – Extra Note: Swap Space Was Mentioned, But Stay Focused

One comment in the source said this:

You should also mention the steps to add swap storage, as explained else on your site: https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04

That’s a good idea in general; swap can help small VPSes.
But adding swap is a separate tutorial.

For this article, we stay focused on the initial root/new-user/sudo setup and the common permission problems.
Once your user and sudo are working correctly, then you can follow a dedicated swap setup guide on your provider’s docs.

Wrap-Up: What You Should Have Working Now

By now, if you slowly followed the logic, you should be able to:

  • Log in as root when needed
  • Use passwd to change the root password
  • Create a new user with adduser
  • Safely edit /etc/sudoers using visudo as root
  • Log in as the new user and successfully run:
    bash
    sudo whoami
  • Understand why visudo can say Permission denied when run without sudo
  • Have a mental checklist for when sudo or SSH “just doesn’t work”

You don’t need to know everything about Linux to manage a small VPS.
You just need a safe process and a bit of patience.

If this saved you time, bookmark CrushEdge for more fixes.

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.