how to add/remove users on linux ?

Posted by

Linux environments have a different ways to handle the user management, check how to add/remove users with simple steps.

These examples were tested on CentOS v 7.2

To create user accounts the specific command you need to use is “useradd” on any common Linux distro, also, if you want to check all the available options related to what you can do with users on Linux, just type “user” and hit on “tab key” in your keyboard to auto-complete the command and you will see something like the following example:

[root@securitytweak ~]# user
useradd userdel userhelper usermod usernetctl users

You can add, delete, get some help, modify and more with this command, for now, we will create a new user and remove it.

To add: you just need to apply the following command in a simple way,

[root@securitytweak ~]# useradd [name]

Example,

[root@securitytweak ~]# useradd securitytweakofficer

And that is it, the new user account has been created, let’s see how to confirm that ? Please check the following file located under the following path,

[root@securitytweak ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
saslauth:x:991:76:Saslauthd user:/run/saslauthd:/sbin/nologin
libstoragemgmt:x:990:988:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:989:984::/run/gnome-initial-setup/:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
securitytweakofficer:x:1001:1001::/home/securitytweakofficer:/bin/bash

You will see at the end of the list the user account that you just created, so, now the next step is to set the new password for this user, to do that use the following command,

[root@securitytweak ~]# passwd [name]

Example,

[root@securitytweak ~]# passwd securitytweakofficer
Changing password for user securitytweakofficer
New password:
BAD PASSWORD: The password fails the dictionary check – it is too simplistic/systematic

This message means that the password you just type, does not met the minimun security requirements.

Retype new password:
passwd: all authentication tokens updated successfully.
[root@securitytweak ~]#

To remove it: Finally, how to remove this user ?

[root@securitytweak ~]# userdel [name]

Example,

[root@securitytweak ~]# userdel securitytweakofficer

And re-type the command to verify on /passwd

[root@securitytweak ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
saslauth:x:991:76:Saslauthd user:/run/saslauthd:/sbin/nologin
libstoragemgmt:x:990:988:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:989:984::/run/gnome-initial-setup/:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin

Now, there is no “securitytweakofficer” user on this host.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s