Explore file and directory permissions. Learn how Linux represents permissions and how you can check the permissions associated with files and directories.
About Google Career Certificates: Google Career Certificates are lessons designed to prepare you for entry-level roles in career fields like cybersecurity, data analytics, digital marketing & e-commerce, IT support, project management, or user experience (UX) design. Google Career Certificates give learners the skills they need to apply for more than 2.4 million in-demand jobs with a median salary of $76,000+.
How To Authorize Users as a Cybersecurity Analyst | Google Cybersecurity Certificate https://youtu.be/0_OCoSR7RWc
Let's continue to learn more about how to work in Linux as a security analyst.
In this video, we'll explore file and directory permissions.
We'll learn how Linux represents permissions and how you can check for the permissions
associated with files and directories. Permissions are the type of access granted
for a file or directory. Permissions are related to authorization.
Authorization is the concept of granting access to specific resources in a system.
Authorization allows you to limit access to specified files or directories.
A good rule to follow is that data access is on a need-to-know basis.
You can imagine the security risk it would impose if anyone could access or modify anything they
wanted to on a system. There are three types of permissions in Linux that an authorized user can
have. The first type of permission is read. On a file, read permissions means contents on the file
can be read. On a directory, this permission means you can read all files in that directory.
Next are write permissions. Write permissions on a file allow modifications of contents
of the file. On a directory, write permissions indicate that new files
can be created in that directory. Finally, there are also execute permissions.
Execute permissions on files mean that the file can be executed if it's an executable file.
Execute permissions on directories allow users to enter into a directory and access its files.
Permissions are granted for three different types of owners. The first type is the user.
The user is the owner of the file. When you create a file, you become the owner of the file,
but the ownership can be changed. Group is the next type. Every user is a part of a certain group.
A group consists of several users, and this is one way to manage a multi-user environment.
Finally, there is other. Other can be considered all other users on the system. Basically,
anyone else with access to the system belongs to this group. In Linux, file permissions are
represented with a 10-character string. For a directory with full permissions for the user
group, this string would be d rwx rwx rwx. Let's examine what this means more closely.
The first character indicates the file type. As shown in this example, d is used to indicate it
is a directory. If this character contained a hyphen instead, it would be a regular file.
The second, third, and fourth characters indicate the permissions for the user. In this example,
r indicates the user has read permissions, w indicates the user has write permissions,
and x indicates the user has execute permissions. If one of these permissions was missing,
there would be a hyphen instead of the letter. In the same way, the fifth, sixth, and seventh
characters indicate permissions for the next owner type, group. As it shows here, the type
group also has read, write, and execute permissions. There are no hyphens to indicate that any of these
permissions haven't been granted. Finally, the eighth through tenth characters indicate
permissions for the last owner type, other. They also have read, write, and execute permissions
in this example. Ensuring files and directories are set with their appropriate access permissions
is critical to protecting sensitive files and maintaining the overall security of a system.
For example, payroll departments handle sensitive information. If someone outside
of the payroll group could read this file, this would be a privacy concern. Another example is
when the user, the group, and other can all write to a file. This type of file is considered a world
writable file. World writable files can pose significant security risks. So how do we check
permissions? First, we need to understand what options are. Options modify the behavior of the
command. The options for our command can be a single letter or a full word. Checking permissions
involves adding options to the ls command. First, ls dash l displays permissions to files and
directories. You might also want to display hidden files and identify their permissions.
Hidden files, which begin with a period before their name, don't normally appear when you use
ls to display file contents. Entering ls dash a displays hidden files.
Then, you can combine these two options to do both. Entering ls dash la displays permissions
to files and directories, including hidden files. Let's get into Bash and try out these options.
Right now, we're in the project's subdirectory. First, let's use the ls command to display its
contents. The output displays the files in this directory, but we don't know anything about their
permissions. By using ls dash l instead, we get expanded information on these files. Let's do
this. The file names are now on the right side of each row. The first piece of information in each
row shows the permissions in the format that we discussed earlier. Since these are all files and
not directories, notice how the first character is a hyphen. Let's focus on one specific file,
project1.txt. The second through fourth characters of its permissions show us the user has both
read and write permissions but lacks execute permissions. In both the fifth through seventh
characters and eighth through tenth characters, the sequence is r hyphen hyphen. This means group
and other have only read privileges. After the permissions, ls dash l first displays a username.
Here, that's us, analyst. Next comes the group name, in our case, the security group.
Now let's use ls dash a. The output includes two more files, hidden files with the names
dot hidden1.txt and dot hidden2.txt. Finally, we can also use ls dash la to show the permissions
for all files including these hidden files. I thought that was pretty interesting, did you?
You now know a little more about file permissions and ownership. This will be helpful when working
in security because monitoring and setting correct permissions is essential for protecting
information. We're going to learn about changing permissions. When working as a security analyst,
there may be many reasons to change permissions for a user. A user may have changed departments
or been assigned to a different work group. A user might simply no longer be working on a project
that requires certain permissions. These changes are necessary in order to protect system files
from being accidentally or deliberately altered or deleted. Let's explore a related command that
helps control this access. In this video, we'll learn about chmod. Chmod changes permissions on
files and directories. The command chmod stands for change mode. There are two modes for changing
permissions, but we'll focus on symbolic. The best way to learn about how chmod works is through
an example. I know this has a lot of details, but we'll break this down. Also, please keep in mind
that, like many Linux commands, you don't have to memorize the information. It can always find
a reference. With chmod, you need to identify which file or directory you want to adjust permissions
for. This is the final argument, in this case, a file named access.txt. The first argument added
directly after the chmod command indicates how to change permissions. Right now, this might seem
hard to interpret, but soon we'll understand why this is called symbolic mode. Previously,
we learned about the three types of owners, user, group, and other. To identify these with chmod,
we use u to represent the user, g to represent the group, and o to represent other. In this particular
example, g indicates we will make some changes to group permissions, and o to permissions for other.
These owner types are separated by a comma in this argument, but do we want to add or take away
permissions? Well, for this, we use mathematical operators. So, the plus sign after g means we want
to add permissions for group, and the minus sign after o means we want to take them away from other.
And the last question is, what kind of changes? We've already learned that r represents read
permissions, w represents write permissions, and x represents execute permissions. So, in this case,
the w indicates that we are adding write permissions to the group, and r indicates that
we are taking away read permissions from other. This is still very complex, but now that we've
broken it down, perhaps it doesn't seem quite so much like a foreign language. And remember,
you don't have to memorize this all. Let's give this new command a try. We'll start out in the
If we use the ls-l command, it will output the permissions for the file.
It shows the permissions for the only file in this directory, access.txt. Previously, we learned how
to read these permissions. The second through fourth characters indicate that the user has
read and write permissions. The fifth through seventh characters show the group only has
read permissions. And the eighth through tenth characters show that other only has read permissions.
We need to adjust these permissions. We want to ensure analysts in the security group have
write permission but take away read permissions from the owner type other. So, we add write
permissions for group and remove read permissions for other. Let's run ls-l again. This shows a
change in the permissions for access.txt. Notice how in the middle segment of permissions for the
group w has been added to give write permissions. And another change is that the r has been removed
in the last segment, indicating that read permissions for other have been removed.
As mentioned earlier, these hyphens indicate a lack of permissions. Now, other is lacking all
permissions. Though it requires practice, working in Linux becomes more natural with time. I'm glad
you're learning a little more about how to use Linux. We are going to discuss adding and deleting
users. This is related to the concept of authentication. Authentication is the process
of a user proving that they are who they say they are in the system. Just like in a physical building,
not all users should be allowed in. Not all users should get access to the system. But we also want
to make sure everyone who should have access to the system has it. That's why we need to add users.
New users can be new to the organization or new to a group. This could be related to a change in
organizational structure or simply a directive for management to move someone. And also, when users
leave the organization, they need to be deleted. They should no longer have access to any part of
the system. Or if they simply change groups, they should be deleted from groups that they are no
longer a part of. Now that we've sorted out why it's important to add and delete users, let's discuss
a different type of user, the root user. A root user or super user is a user with elevated privileges
to modify the system. Regular users have limitations where the root does not. Individuals who need to
perform specific tasks can be temporarily added as root users. Root users can create, modify, or delete
any file and run any program. Only root users or accounts with root privileges can add new users.
So you may be wondering how you become a super user. Well, one way is logging in as the root user,
but running commands as the root user is considered to be bad practice when using Linux.
Why is running commands as a root user potentially problematic? The first problem with logging in
as root is the security risks. Malicious actors will try to breach the root account. Since it's
the most powerful account, to stay safe, the root account should have logins disabled.
Another problem is that it's very easy to make irreversible mistakes. It's very easy to type
the wrong command in the CLI, and if you're running as a root user, you run a higher risk of
making an irreversible mistake, such as permanently deleting a directory. Finally, there's the concern
of accountability. In a multi-user environment like Linux, there are many users. If a user is
running as root, there is no way to track who exactly ran a command. One solution to help solve
this problem is sudo. Sudo is a command that temporarily grants elevated permissions to
specific users. This provides more of a controlled approach compared to root, which runs every command
with root privileges. Sudo solves lots of problems associated with running as root.
Sudo comes from superuserdo and lets you execute commands as an elevated user without having to
sign in and out of another account. Running sudo will prompt you to enter the password for the user
you're currently logged in as. Not all users on a system can become a superuser. Users must be
granted sudo access through a configuration file called the sudoers file. Now that we've learned
about sudo, let's learn how we can use it with another command to add users. This command is
useradd. Useradd adds a user to the system. Only root or users with sudo privileges can use a useradd
command. Let's look at a specific example in which we need to add a user. We'll imagine a new
representative is joining the sales department and will be given the username of salesrep7.
We're tasked with adding them to the system. Let's try adding the new user. First, we need to use
a sudo command followed by the useradd command. And then last, the username we want to add, in this
case salesrep7. This command doesn't display anything on the screen, but since we get a new
bash cursor and not an error message, we can feel confident that the command worked successfully.
If it didn't, an error message would have appeared. Sometimes an error has to do with something simple
like misspelling useradd. Or it might be because we didn't have sudo privileges.
Now let's learn how to do the opposite. Let's learn how to delete a user with userdel. Userdel
deletes a user from the system. Similarly, we need root permissions that we'll access through sudo
to use userdel. Let's go back to our example of the user we added. Let's imagine two months later
the sales representative we just added to the system leaves the company. That user should no
longer have access to the system. Let's delete that user from the system. Again, the sudo command is
used first. Then we add the userdel command. Last, we add the name of the user we want to delete.
Again, we know it ran successfully because there is a new bash cursor and not an error message.
Now we've covered how to add and delete users and how these actions require sudo.
When using sudo, we have to use our best judgment.
These special privileges must be used responsibly to ensure a secure system.