User Profiles
User profiles are environment settings loaded at login, defined in dotfiles within a user’s home directory. They control shell behavior, aliases, and environment variables.
Key Profile Files:
~/.profile: For login shells (e.g., SSH). Sets environment variables likePATH.~/.bashrc: For interactive non-login shells (new terminals). Sets aliases and functions.~/.bash_profile: If this exists, it’s read by login shells instead of.profile./etc/profile&/etc/bash.bashrc: System-wide versions of these files for all users.
Example .bashrc content:
# Set custom prompt
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# User specific aliases
alias ll='ls -alF'
alias grep='grep --color=auto'Locking Accounts
Locking an account prevents a user from logging in without deleting their data. This is useful for temporary suspensions or security investigations.
To lock the account for user ‘john’:
sudo usermod -L johnTo unlock the account:
sudo usermod -U johnSetting Passwords
The passwd command is used to set or change user passwords.
To set a password for a new user ‘student’ (as root/sudo):
sudo passwd studentTo force a user to change their password on next login:
sudo chage -d 0 studentSwitching Users (su)
The su (substitute user) command allows you to switch to another user account. Using the - or -l flag is recommended as it simulates a full login, loading the target user’s complete environment.
To switch to the root user (and load root’s environment):
su -To switch to user ‘jane’ (loading her environment):
su - janeSwitching Groups (newgrp)
The newgrp command allows a user to temporarily change their primary group to another group they are a member of. This is useful when you need to create files with a specific group ownership.
Switch primary group to ‘developers’:
newgrp developersAny new files created in this new shell will have ‘developers’ as their group owner. Type exit to return to your previous shell.
Removing Users (userdel)
The userdel command is used to remove a user account. Using the -r flag is highly recommended to also remove the user’s home directory and mail spool.
To remove a user ‘tempuser’ and their home directory:
sudo userdel -r tempuserTo remove a user but keep their home directory (for data preservation):
sudo userdel olduser