Linux User Management Deep Dive Flashcards
What 2 shortcuts of cding into home dir do you know?
cd ~
cd $HOME
How to create a new user with his full name description, specify and create new home dir, set primary and secondary group, set a password, specify a shell, and specify UID all with a SINGLE COMMAND?
useradd -c “[user description]” -d [path to home dir] -m -g [primary group] -G [secondary group] -p [password] -s [path to shell] -u [uid] [username]
How to change users primary group, change secondary group, append secondary group?
usermod -g [primary group] -G [secondary group] [user name] - change primary group, and set secondary group to the one typed in this command
usermod -aG [group] [user] - append secondary group
How to change user’s home directory to a new one, and move content of the old home dir into the new one?
usermod -d [new home dir path] -m [username]
Where are default new user’s profile files stored?
/etc/skel
Whrere is GID conf file stored?
/etc/login.defs
How to create a group with GID of 30045?
groupadd -g 30045 [groupname]
What is the difference between primary and secondary group?
Primary group – Specifies a group that the operating system assigns to files that are created by the user. Each user must belong to a primary group.
Secondary groups – Specifies one or more groups to which a user also belongs. Users can belong to up to 15 secondary groups.
How to change group ID and group name?
groupmod -g [new GID] -n [new name] [old name]
Can you remove a group that is some user’s primary group?
yes, with a grupdel -f [groupname] command
without “-f” the shell won’t allow us to do this
How to change password for a group? How to remove it?
gpasswd [groupname] - changes password
gpasswd -r [groupname] - removes it
How to add many users to a group with a single command?
gpasswd -M [user1],[user2],[user3] [group name]
How to run a integration test of user and group config files?
pwck
grpck
How the “last resort” troubleshooting /etc/passwd and /etc/group commands work?
The pwconv command creates shadow from passwd and an optionally
existing shadow.
The pwunconv command creates passwd from passwd and shadow and then removes shadow. The grpconv command creates gshadow from group and an optionally existing gshadow. The grpunconv command creates group from group and gshadow and then removes gshadow.
What types of UID there are?
0 - root
1-999 - system/application users
1000+ normal users
What is a shell and what are a few of it types? Where are they located?
Simply put, the shell is a program that takes commands from the keyboard and gives them to the operating system to perform. In the old days, it was the only user interface available on a Unix-like system such as Linux. Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such as the shell.
Bourne-Again Shell - /bin/bash
Bourn Shell - /bin/sh
Korn Shell - /bin/ksh
How to print a message for given user login attempt, and not allow that user to login into system?
We would have to change his login bash to /sbin/nologin. We would have to put message into /etc/nologin.txt file.
How to not allow an user to log in into the system at all?
Change user shell to /bin/false
or /sbin/nologin
How to allow only the root user to login into the system?
We have to create /etc/nologin file. (we can write the message in it that will display upon user’s login attempt)
Give a few examples of config files from user’s home directory?
.bash_profile
.bashrc
.bash_logout
How is /etc/passwd built?
username:x:UID:primary group GID:comment:home dir:login shell
x - password is stored in /etc/shadow file
How is /etc/gshadow built?
groupname:password:group admins:group members
password field can either have:
- encrypted password
- ”!” - no user is allowed to access the group using the newgrp command.
- ”!!” - A value of !! is treated the same as a value of ! — however, it also indicates that a password has never been set before.
- null - If the value is null, only group members can log into the group.
how is /etc/shadow built?
username:password:days after the 1.1.1970 that the password was last changed:minimum amount of days that the password can be changed:maximum amount of days before the password has to be changed:days before password expiration that the users gets warning message:days after password expiration that the user is disable:days since 1.1.1970 that the password expires
password field can either have encrypted password, or “!!” which means that the account is locked, as the password has never been set
how is /etc/group built?
name:x:GID:to which users group is set as secondary
x indicated that password info is stored in /etc/gshadow