Linux - chown

1. pwd Command

pwd stands for Print Working Directory.
It shows the current directory path where you are located in the terminal.

Example:

pwd

Output:

/home/user/Documents

2. useradd and userdel in Linux

These commands are used for managing user accounts.

useradd

Creates a new user account.

Example:

useradd john

Creates a user named john.

Create user with home directory:

useradd -m john

Set password for a new user:

passwd john

userdel

Deletes a user account.

Example:

userdel john

Removes the user but keeps their home directory.

Delete user along with home directory:

userdel -r john

3. groupadd and groupdel

Used to manage Linux groups.

groupadd

Creates a new group.

Example:

groupadd developers

groupdel

Deletes an existing group.

Example:

groupdel developers

4. Sudo Privileges

sudo stands for Superuser Do. It allows a regular user to run commands with root (administrator) privileges.

Examples:

sudo apt update

Runs the command with elevated privileges.

To give a user sudo rights:

  1. Add user to the sudo group:

usermod -aG sudo username
  1. Or configure via sudoers file:

visudo

Advantages of sudo:

  • Provides controlled root access

  • Logs all admin activities

  • Secures the system from accidental misuse


5. chmod – File Permissions & Access Control

chmod changes the permissions of a file or directory.

Linux permissions:

  • r = read

  • w = write

  • x = execute

Three permission levels:

  • User (owner)

  • Group

  • Others

Example: Give execute permission

chmod +x script.sh

Example: Numeric permissions

chmod 755 file.sh

Meaning:

  • 7 = rwx (owner)

  • 5 = r-x (group)

  • 5 = r-x (others)

Example: Remove write permission for others

chmod o-w file.txt

6. chown – Change File Ownership

chown changes the owner and/or group of a file or directory.

Change owner:

chown john file.txt

Change owner and group:

chown john:developers file.txt

Change ownership of a folder recursively:

chown -R john:developers /home/john/