Linux - User (Uid)

Introduction

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

Identifier

The numeric identifier are:

  • The user identifier: called a UID (user ID).
  • The group identifier: called the GID (group ID)

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:

  • the root account (the superuser, who has permission to do anything),
  • the root account's home directory (/root)
  • and the root directory for the entire file system (/).

Group

Each user:

  • must belong to a primary group
  • may belong to several secondary groups for authorization purposes.

How to display user and group information

User id

The User Id can seen with:

  • The id command:
id
uid=0(root) gid=0(root) groups=0(root)

  • With the environment variable $UID, you get the User ID number
if [ "${UID}" -eq 0 ]; then
  echo "I'm root"
fi

Default directories

  • /home — Default location for users' home directories. For example, a user with the username foo has the home directory /home/foo
  • /tmp — The reserved directory for all users to store temporary files. Files stored here are not permanent. A system process removes old files from this directory on a periodic basis. Do not write any files or directories that you want to keep here.

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:

  • Red Hat Linux:
    • RHEL4 and higher: system-config-users
    • User Manager: redhat-config-users.
  • SUSE Linux: yast or yast2

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:

  • all users
cut -d: -f1 /etc/passwd
  • All users who contains the letters “vis” in their names (use the pipe symbol followed by the grep executable which has a pattern as input: '.*vis')
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:

  • -d home directory
  • -s starting program (shell)
  • -p password
  • -g (primary group assigned to the users)
  • -G (Other groups the user belongs to)
  • -m (Create the user's home directory)

Example: To add a new user with

  • a primary group of oinstall
  • a second group dba
  • starting shell /bin/bash
  • password of xxxx
  • home directory of gerardnico
  • create home directory
  • a login name of gerardnico
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:

  • -d home directory
  • -s starting program (shell)
  • -p password
  • -g (primary group assigned to the users)
  • -G (Other groups the user belongs to)

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:

  • -r (remove home directory)

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)





Discover More
Bash Liste Des Attaques Ovh
Bash - (Builtin|Intern|System|Reserved|Shell) variable name

Reserved variable name are named that have a special meaning for the bash shell. PS1 defines the shell's command-line prompt. HOME defines the home directory for a user. PATH defines a list...
Bash Liste Des Attaques Ovh
Bash - Complete (Builtin command) - Completion

The programmable completion feature in Bash permits typing a partial command, then pressing the [Tab] key to auto-complete the command sequence The process of applying these completion specifications...
Bash Liste Des Attaques Ovh
Bash - Runuser

Runuser - run a shell with substitute user and group IDs, similar to su, but will not run Linux_PAMLinux Pluggable Authentication Modules (PAM) hooks Basic From the init library:
Yarn Hortonworks
HDFS - (User) Authentication, Identification

in HDFS. See also: adminusers User identity mechanism is specified by the configuration property: hadoop.security.authentication simple: same as OS kerberos The user is the Linux user....
Card Puncher Data Processing
How to create/modify a User in Ansible?

user management in Ansible - An how to of the User module of Ansible where: vault_dev_login_password is a vault variable (encrypted)...
Linux - /etc/passwd (public user information)

/etc/passwd is the text file that contains public user account information The name is a little bit misleading because the password is no more present (replaced with a X) as this file is used by many...
Linux - /etc/shadow (Secure user information)

/etc/shadow is a text file that contains secure user information such as: password. and account expiration information The public user information are stored in the /etc/passwd file. The shadow...
Linux - Group (Gid)

Every user who has access to a Linux system needs a login and a password. Each user must belong to a primary group and for security or access purposes can belong to several secondary groups. The easiest...
Linux - Password (User)

user password are password of a user stored in the secure shadow file. The password is the second field of the shadow file It's 13 character encrypted A blank entry (eg. ::) indicates a password...
Linux - Resource Manager - Processes limitations (/etc/security/limits.conf)

Limiting user processes is important for running a stable system. To limit user process resource, you have just to set shell limit by adding: a user name or group name or all users to /etc/security/limits.conf...



Share this page:
Follow us:
Task Runner