Table of Contents

Linux - User (Uid)

Introduction

Every user who has access to a Linux system needs a login and a password.

Identifier

The numeric identifier are:

These identifiers are mapped to a name identifier known as username and group name in the /etc/passwd

Root User

The root login is the super admin user and as the UID 0

In order to create new logins, and modify or delete users, you must already be logged in as root.

The term root may refer to:

Group

Each user:

How to display user and group information

User id

The User Id can seen with:

id
uid=0(root) gid=0(root) groups=0(root)

if [ "${UID}" -eq 0 ]; then
  echo "I'm root"
fi

Default directories

Default file - The skeleton directory

The /etc/skel/ directory is for “skeleton” user files, which are used to populate a home directory when a user is first created. This directory can be modified to fit your needs. Modifications only effect new users and does not change anything for existing users.

Management

Tools and GUI

The easiest way to manage users and groups is through the graphical applications:

The following table lists the available commands line for managing users and groups:

Task Command
Creating groups Linux - Group (Gid)
Modifying groups Linux - Group (Gid)
Deleting groups Linux - Group (Gid)
Creating users useradd
Modifying users usermod
Deleting users userdel
Change/set a password. passwd
Switch to another user su
Verification of the password, group, and associated shadow files pwck: verify integrity of password files
grpck
Conversion to shadow passwords and back to standard passwords pwconv, pwunconv

List

User names and primary groups are stored in /etc/passwd

Example:

cut -d: -f1 /etc/passwd
cat /etc/passwd | grep -i '.*vis'
oravis:x:502:502::/home/oravis:/bin/bash
applvis:x:503:502::/home/applvis:/bin/bash

create

useradd

the useradd command add a new user.

Options:

Example: To add a new user with

useradd -g oinstall -G dba -s /bin/shell -p xxxx -d /home/gerardnico -m gerardnico

ansible

user module

- name: "Sqlline - Create the group"
  group:
    name: '{{ sqlline_group }}'
    state: present

- name: "Sqlline - Create the user"
  user:
    name: '{{ sqlline_owner }}'
    comment: Sqlline Installation user
    shell: /bin/bash
    state: present
    group: '{{ sqlline_group }}'
    password: {{ upassword | password_hash('sha512') }}

Set

Usermode

This command usermod modifies an existing user. You must use all the options in the same way as you create it.

Options:

Example: To add the group 'others' to the user gerardnico

usermod -G others gerardnico

To suppress a group for a user using the command line, you will have to list all the groups that you want the user in. For example if the user currently in group1,group2,group3,group4 and you want him out of group3 then

usermod -G group1,group2,group4 loginName

Delete

userdel

This command delete a a user,

Options:

Example: To remove the user 'gerardnico' and his home directory

[root@ebs121 /]# userdel -r gerardnico
bash: userdel: command not found
[root@ebs121 /]# /usr/sbin/userdel -r gerardnico

Password

See Linux - Password (User)