Essential Linux Commands for Managing Passwords and Permissions
Written on
Chapter 1: Introduction to Linux Commands
Linux is a widely-used operating system among developers, making it beneficial to familiarize oneself with various commands. This article highlights several essential Linux commands that every developer should know.
Section 1.1: The wc Command
The wc command is used to count lines, words, or bytes within a file. For example, to count the lines in a file named test.txt, you would execute:
wc -l test.txt
To count the words in the same file, use:
wc -w test.txt
For byte count, the command is:
wc -c test.txt
Additionally, the -m flag can be used to get an accurate byte count.
Section 1.2: Opening Files and Directories
The open command allows users to access files, directories, and applications. To open a specific file, simply run:
open filename
If you wish to open the current directory, use:
open .
Section 1.3: Changing Passwords
The passwd command is utilized for modifying a user’s password. When executed, it prompts for the current password and the new password you wish to set. Superusers can also change another user's password using:
passwd username
Section 1.4: Modifying File Permissions with chmod
The chmod command enables users to alter file permissions. To change permissions, the command format is as follows:
- a for all
- u for user
- g for group
- o for others
You can add permissions using + or remove them using -. Permission types include:
- r — read
- w — write
- x — execute
For instance, to grant read permission to all users for a file named filename, use:
chmod a+r filename
To revoke read permission from both the group and others, the command would be:
chmod og-r filename
Permissions can also be set numerically. Each number corresponds to permission levels:
- 0 — no permissions
- 1 — execute
- 2 — write
- 3 — write and execute
- 4 — read
- 5 — read and execute
- 6 — read and write
- 7 — read, write, and execute
To set full permissions for everyone, you would run:
chmod 777 filename
Section 1.5: Changing File Ownership
To change the owner of a file or directory, the chown command is utilized. The syntax is:
chown newuser filename
For example, to transfer ownership of test.txt to a user named user, you would execute:
chown user test.txt
To change ownership recursively, add the -R flag:
chown -R newuser directoryname
You can also assign ownership to a group using:
chown :groupname filename
For instance, to change the owner of test.txt to bob in the users group, use:
chown bob:users test.txt
Section 1.6: Modifying Groups with chgrp
The chgrp command allows you to change the group ownership of a file. The command format is:
chgrp newgroup filename
Conclusion
Understanding how to change file permissions, count file sizes, and manage passwords is crucial for effective use of Linux commands.
This video titled "Linux Back to Basics Episode 5: Users and Permissions" provides a comprehensive overview of managing users and their permissions in Linux, perfect for beginners.
The second video, "Linux Commands Part 5," dives deeper into various Linux commands, enhancing your command line skills.