Linux User Accounts (SEC 300) - Chromosom3/TechNotes GitHub Wiki
Linux User Accounts & File Permissions
Creating new user:
Command: useradd
Switches:
- -m : Adds (creates) user's home directory.
- -d PATH : Specifies the path for the home directory
- -k PATH : Specifies the skeleton directory.
- -s PATH : Specifies the shell the user is going to use.
Example: useradd -m -d /home/dylan -k /etc/skel/ -s /bin/bash dylan
Default values are stored in /etc/default/useradd
Creating a new group:
Command: groupadd
Example: groupadd marketing
This creates the group marketing.
Adding a user to a group:
Command: usermod
Switches:
- -aG : Adds a user to a group
Example: usermod -aG marketing bob
This adds Bob to the marketing group.
Password Information/Policy:
Command: chage USER
Switches:
- -l : Lists
Example: chage -l dylan
More: /etc/login.defs contains password max days, password min days, and warn age. /etc/default/useradd is the file that is read when a user is added. Video shows changing the shell from sh to bash. Making bash the default shell for new users. If you change #INACTIVE=-1 to INACTIVE=0 the account will no longer be able to login when the password expires. If you change the SKEL value you dont need to specify -k PATH.
/etc/skel/:
Path: /etc/skel/
Description: /etc/skel/ is the folder that contains any files or folders you want set up for users. Contains a minimum set of files (default files). Can add directories such as Downloads, Pictures, etc.)
{} in mkdir:
Description: When using mkdir you can specify multiple folders by using {}. The below command will create a Pictures folder and Documents folder in /etc/skel/
Example: mkdir /etc/skel/{Pictures,Documents}
List Directory:
Command: ls
Switched:
- -l : List content of a directory.
- -d : list permissions of the directory.
Example: ls -ld /home/dylan
Changing file/directory owner:
Command: chown
Example: chown bob somefile.txt
This sets Bob as the owner of somefile.txt.
Changing file/directory group:
Command: chgrp
Example: chgrp marketing /marketing/
This sets the marketing group as the owner group for the marketing folder.
Change File/Folder Permissions:
Command: chmod PATH
Description: Changes the permissions for a file or folder. Can either use rwx or numbers for perms. See the table below for numbers.
Examples:
chmod 700 /home/dylan
: Makes it so the owner has full read, write, and execute. The owner group and others have no permissions.chmod o-rwx /home/dylan
: Makes it so other loses all permissions if they have any.chmod g+rwx /home/dylan
: Makes it so the owner group can have full permissions.