Linux Debian user commands

These commands have come in handy a lot over the last couple of days, as I have been setting up Xen with a few Virtual Machines.

Replace [user] in the commands below with the name of your user (e.g. mike). If you need a good password it is recommended you use a strong one.

Add a user #

How to add a user on linux via command line:

$ adduser [name]

Reset password #

How to reset a user's password on command line:

$ passwd [name]

Delete user #

Delete a linux user via command line:

$ deluser [name]

Give user sudo privileges #

There are several ways you can add a user to the sudoers group - it is advised you stick to one method for each server.

You can see if there are users in the sudoers group with the following command:

$ grep -i --color sudo /etc/group

Add the user to the sudo "group" #

If this is on a brand new server, you may need to apt-get install sudo

$ adduser [name] sudo

Add the user to the sudoers file #

Edit the following file (must be done as root or someone with existing sudo privileges

sudo visudo

And add the following to the file:

username ALL=(ALL)   ALL

Alternatively, you can do it with one command:

echo ' username ALL=(ALL)   ALL' >> /etc/sudoers

List all the users on the system #

$ cut -d: -f1 /etc/passwd

This will list out all the users - including system ones

Don't require password for sudo #

Open the sudoers file:

$ sudo visudo

And add one of the following lines to the bottom of the file:

For a specific user:

[name] ALL=(ALL) NOPASSWD: ALL

For a group: (e.g. if the user is in the sudo group

%sudo ALL=(ALL) NOPASSWD: ALL
Mike Street

Written by Mike Street

Mike is a front-end developer from Brighton, UK. He spends his time writing, cycling and coding. You can find Mike on Twitter.