Before we go
I have tested all the steps many times on Debian 11 by Virtual Machine Snapshots. It can be reproduced step by step.
Anytime the message notices you to provide the password, just input it. Make sure you remember the correct password.
First of all, log in your Debian system as the common user which was created while installing the system.
Then use the command
su -
to get the root privilege.
Here is the most important part:
Because Debian’s clean-up image doesn’t preinstall sudo, you should install it first.
Use the command
apt update
apt install sudo
to get sudo ready.
Then we can set the common user into sudo group by the command
usermod -aG sudo <username>
Here is another important part. Please read it carefully.
Now we need to make sudo active, you have two options:
Option 1 (reboot needed):
Keep current state as root, use command
reboot
to restart your server and then log in your server with the common user again.
Option 2 (no reboot needed):
use the command
su - <username>
to activate the new sudo user at once.
Done
Now everything is okay, you can enjoy sudo as you wish.
Tips
We can use Ctrl + D to log out as the common user and test if sudo command is active. This is very convenient.