0% found this document useful (0 votes)
2 views

13. User Customization

The document provides instructions on user administration in a Linux environment, detailing the configuration of user accounts using the 'useradd' command with various options. It covers setting user attributes such as UID, GID, home directory, login shell, and group assignments, along with examples of creating users with specific configurations. Additionally, it discusses account expiration and inactive periods, as well as creating system users.

Uploaded by

Bhupesh Kanire
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

13. User Customization

The document provides instructions on user administration in a Linux environment, detailing the configuration of user accounts using the 'useradd' command with various options. It covers setting user attributes such as UID, GID, home directory, login shell, and group assignments, along with examples of creating users with specific configurations. Additionally, it discusses account expiration and inactive periods, as well as creating system users.

Uploaded by

Bhupesh Kanire
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

User Administration with Customization

[root@localhost ~]# vim /etc/default/useradd

# useradd defaults file

GROUP=100

HOME=/home

INACTIVE=-1

EXPIRE=

SHELL=/bin/bash

SKEL=/etc/skel

CREATE_MAIL_SPOOL=yes

syntax:

# useradd <option> <argument> <username>

# Options:

-o  non unique

-u  uid

-g  gid

-d  home directory

-b  base directory

-c  comment

-s  login shell

-p  password

-f  inactive password

-G  group assign

-e  account expiry
-r  system user

#eg:

[root@localhost ~]# useradd jack

[root@localhost ~]# tail -1 /etc/passwd

jack:x:1001:1001::/home/jack:/bin/bash

-u --> userid

[root@localhost ~]# useradd -u 2020 user1

[root@localhost ~]# tail -1 /etc/passwd

user1:x:2020:2020::/home/user1:/bin/bash

-g --> groupid

[root@localhost ~]# useradd -g 2121 user2

useradd: group '2121' does not exist

[root@localhost ~]# groupadd admin

[root@localhost ~]# tail -1 /etc/group

admin:x:2021:

[root@localhost ~]# useradd -g 2021 user2  users primary group will not be created

[root@localhost ~]# tail -1 /etc/passwd

user2:x:2021:2021::/home/user2:/bin/bash

[root@localhost ~]# tail -3 /etc/group

jack:x:1001:

user1:x:2020:
admin:x:2021:

[root@localhost ~]# useradd -g admin user3

[root@localhost ~]# tail -1 /etc/passwd

user3:x:2022:2021::/home/user3:/bin/bash

[root@localhost ~]# tail -3 /etc/group

jack:x:1001:

user1:x:2020:

admin:x:2021:

[root@localhost ~]# id user2

uid=2021(user2) gid=2021(admin) groups=2021(admin)

[root@localhost ~]# id user3

uid=2022(user3) gid=2021(admin) groups=2021(admin)

-N --> do not create users primary group

[root@localhost ~]# useradd -N user4

[root@localhost ~]# tail -1 /etc/passwd

user4:x:2023:100::/home/user4:/bin/bash  system group will be allocated to user,

[root@localhost ~]# tail /etc/group

gdm:x:42:

gnome-initial-setup:x:975:

sshd:x:74:

slocate:x:21:
rngd:x:974:

tcpdump:x:72:

student:x:1000:

jack:x:1001:

user1:x:2020:

admin:x:2021:

[root@localhost ~]# cat /etc/group

ftp:x:50:

lock:x:54:

audio:x:63:

users:x:100:

[root@localhost ~]# id user4

uid=2023(user4) gid=100(users) groups=100(users)

-c --> comment

[root@localhost ~]# useradd -c "redhat_user" user5

[root@localhost ~]# tail -1 /etc/passwd

user5:x:2024:2024:redhat_user:/home/user5:/bin/bash

[root@localhost ~]# tail -1 /etc/group

user5:x:2024:

-s --> login shell

[root@localhost ~]# useradd -s /bin/sh user6


[root@localhost ~]# tail -1 /etc/passwd

user6:x:2025:2025::/home/user6:/bin/sh

[root@localhost ~]# echo "redhat" | passwd user6 --stdin

Changing password for user user6.

passwd: all authentication tokens updated successfully.

[root@localhost ~]# tail -1 /etc/shadow

user6:$6$x9rpH/LaNdvR9Q5N$zLd30C7V0kfIYEYo2qgkgIsWdVPcuLjmi1aYWHOPwjreCJjtrCZ5ejpwD4
GZdWGQvY2zyqMhrziTBmQ3dp2z./:19033:0:99999:7:::

#now login to user6 account

#alt+ctrl+F1login

User will get sh shell after

#alt+ctrl+F1

Login with root account

[root@localhost ~]# su - user6

[user6@localhost ~]$ echo $0

-sh

[user6@localhost ~]$ exit

logout

-d --> home directory

[root@localhost ~]# # useradd command will create users home directory in /home by default
setting. but we can customize
[root@localhost ~]# useradd -d /userdata user7

[root@localhost ~]# tail -1 /etc/passwd

user7:x:2026:2026::/userdata:/bin/bash

[root@localhost ~]# su - user7

[user7@localhost ~]$ pwd

/userdata

[user7@localhost ~]$ touch apple

[user7@localhost ~]$ ls

apple

[user7@localhost ~]$ ll

total 0

-rw-rw-r--. 1 user7 user7 0 Feb 10 20:14 apple

[user7@localhost ~]$ exit

Logout

[root@localhost ~]# ls /

bin dev home lib64 mnt proc run srv tmp usr

boot etc lib media opt root sbin sys userdata var

[root@localhost ~]# ls -ld /userdata/

drwx------. 4 user7 user7 126 Feb 10 20:15 /userdata/

-b --> base directory

/home/jack

/home --> base directory. , jack --> home directory


[root@localhost ~]# mkdir /base_dir

[root@localhost ~]# ls /

base_dir boot etc lib media opt root sbin sys userdata var

bin dev home lib64 mnt proc run srv tmp usr

[root@localhost ~]# useradd -b /base_dir user8

[root@localhost ~]# tail -1 /etc/passwd

user8:x:2027:2027::/base_dir/user8:/bin/bash

[root@localhost ~]# su - user8

[user8@localhost ~]$ pwd

/base_dir/user8

[user8@localhost ~]$ touch abc

[user8@localhost ~]$ ls

abc

[user8@localhost ~]$ exit

logout

[root@localhost ~]# ls -ld /base_dir/user8/

drwx------. 4 user8 user8 124 Feb 10 20:22 /base_dir/user8/

[root@localhost ~]# ls /base_dir/user8/

abc

-G --> assign group

[root@localhost ~]# groupadd testing


[root@localhost ~]# groupadd sales

[root@localhost ~]# tail -2 /etc/group

testing:x:2029:

sales:x:2030:

[root@localhost ~]# useradd -G testing,sales user9

[root@localhost ~]# tail -1 /etc/passwd

user9:x:2029:2031::/home/user9:/bin/bash

[root@localhost ~]# tail /etc/group

testing:x:2029:user9

sales:x:2030:user9

user9:x:2031:

[root@localhost ~]# useradd -G 2029 user10

[root@localhost ~]# tail -3 /etc/group

sales:x:2030:user9

user9:x:2031:

user10:x:2032:

[root@localhost ~]# tail -4 /etc/group

testing:x:2029:user9,user10

sales:x:2030:user9

user9:x:2031:

user10:x:2032:

-e --> expiry date

[root@localhost ~]# useradd -e "31 dec 2022" user11

[root@localhost ~]# tail -1 /etc/passwd


user11:x:2031:2033::/home/user11:/bin/bash

[root@localhost ~]# tail -1 /etc/shadow

user11:!!:19033:0:99999:7::19357:

[root@localhost ~]# chage -l user11

Last password change : Feb 10, 2022

Password expires : never

Password inactive : never

Account expires : Dec 31, 2022

Minimum number of days between password change :0

Maximum number of days between password change : 99999

Number of days of warning before password expires :7

-f --> inactive period

[root@localhost ~]# useradd -f 10 user12

[root@localhost ~]# tail -1 /etc/passwd

user12:x:2032:2034::/home/user12:/bin/bash

[root@localhost ~]# tail -1 /etc/shadow

user12:!!:19033:0:99999:7:10::

[root@localhost ~]# chage -l user12

Last password change : Feb 10, 2022


Password expires : never

Password inactive : never

Account expires : never

Minimum number of days between password change :0

Maximum number of days between password change : 99999

Number of days of warning before password expires :7

r --> create system user

[root@localhost ~]# useraad -r user13

[root@localhost ~]# useradd -r user13

[root@localhost ~]# tail -1 /etc/passwd

user13:x:974:973::/home/user13:/bin/bash

[root@localhost ~]# useradd -u 5050 -g 1000 -s /bin/sh -d /user_home -c "RHCSA_USER" -G


testing,sales -e "21 mar 2022" john

[root@localhost ~]# tail -1 /etc/passwd

john:x:5050:1000:RHCSA_USER:/user_home:/bin/sh

[root@localhost ~]# tail /etc/group

testing:x:2029:user9,user10,john

sales:x:2030:user9,john

user9:x:2031:

[root@localhost ~]# tail -1 /etc/shadow

john:!!:19033:0:99999:7::19072:

[root@localhost ~]# id john


uid=5050(john) gid=1000(student) groups=1000(student),2029(testing),2030(sales)

[root@localhost ~]# groups john

john : student testing sales

You might also like