Linux System Administration

0 of 83 lessons complete (0%)

Managing User Accounts

User Management and Shells

You don’t have access to this lesson

Please register or sign in to access the course content.

Lab: Linux Shells & User Management

Linux Fundamentals

Shells, User Management, and Permissions

Shells

A shell is a command-line interpreter that provides a user interface for accessing the operating system’s services. It’s where you type commands that the kernel then executes.

Common Shells in Linux:

  • Bash (Bourne-Again SHell): The most common default shell, valued for its ubiquity and powerful scripting.
  • Zsh (Z Shell): A highly customizable shell with advanced features like improved tab completion and plugin support.
  • Sh (Bourne Shell): An older, simpler shell that Bash is largely compatible with.

Checking and Changing Shells:

To see your current shell:

echo $SHELL
/bin/bash

To see the default shell for user ‘john’:

grep ^john /etc/passwd
john:x:1001:1001:John Doe,,,:/home/john:/bin/bash

To change your own shell to Zsh:

chsh -s /bin/zsh

Restricted Shells

A restricted shell limits the commands and actions a user can perform, often used for security purposes. The most common is rbash.

Example: Setting a user’s shell to rbash

sudo usermod -s /bin/rbash newuser

User Management Commands

Linux provides several command-line utilities for managing user and group accounts. These commands require root privileges (or sudo) to execute.

CommandDescriptionExample Usage
useraddCreates a new user.sudo useradd -m student
usermodModifies a user.sudo usermod -aG sudo student
userdelDeletes a user.sudo userdel -r tempuser
passwdSets a password.sudo passwd student
groupaddCreates a new group.sudo groupadd developers
groupmodModifies a group.sudo groupmod -n dev team
groupdelDeletes a group.sudo groupdel oldgroup
idDisplays user/group IDs.id student
groupsDisplays user’s groups.groups student

Homes and Permissions

Every user account has a home directory (e.g., /home/username) to store personal files. Proper permissions are crucial for privacy and security.

Understanding Permissions

Let’s break down a permission string like drwxr-xr-x:

  • d: The entry is a directory. For a file, this would be a dash (-).
  • rwx: The first set of three characters defines permissions for the owner (user). `r`=read, `w`=write, `x`=execute.
  • r-x: The second set defines permissions for the group. This group can read and execute, but not write.
  • r-x: The final set defines permissions for others (all other users).

Permissions are also represented by numbers (octal notation), where `r=4`, `w=2`, and `x=1`. So, `rwx` is `4+2+1=7` and `r-x` is `4+0+1=5`. Therefore, `rwxr-xr-x` is `755`.

Managing Permissions:

Checking permissions of a home directory:

ls -ld /home/john
drwxr-xr-x 4 john john 4096 Aug 03 20:37 /home/john

Changing a file’s permissions to be readable/writable only by the owner (600):

chmod 600 /home/john/private_doc.txt

Changing the owner of a file:

sudo chown admin /path/to/file.txt

Changing the group owner of a file:

sudo chgrp developers /path/to/project_file.txt