 We've seen the basics of permissions in a Unix-based operating system in a previous demo where we saw that files and directories have read, write and execute permissions and those permissions can be set for the user owner, the group owner or other users. And we've seen that we can switch between users using SU and execute programs as the administrator user or the root user using sudo. Now let's see how we can change permissions on files, including changing the owner and group of a file. I'm currently logged in as the user sgordon. If I look at the contents of my directory, a set of files and directories, let's focus on the file example.txt. I'll just clear and show again example.txt. The permissions for the user owner, which is sgordon, the current user I'm logged in as, read the file, write the file, but not execute permissions. The permissions for members of the faculty group read, but no write or execute permissions. For other users, there are no permissions. How do we change the permissions on this file? We use the program chmod, where we specify for what set of users we want to change the permissions for. They can be for the current user owner, the group owner, other users or for all users. And we specify what we want to do. We want to add a permission or revoke or minus a permission and what specific permission we want to apply, read, write or execute. For example, let's say I want to add the permission for other users to read the file example.txt. Currently other users have no permissions. I want to add the read permission for other users. So in chmod for other users, I'll use o. Add the permission plus read permissions are followed by the file name. And now let's look and check. We see we've gone from no permissions for the file. We added the read permission for other users, which is indicated now that other users can read this file. And we can use different combinations of the read, write, execute permissions of adding and revoking permissions plus and minus for users, groups, other users and all users. Let's try some more examples. Let's add write permissions to the file for members of the faculty group. So the group owner is the faculty group currently has read permissions only. Let's add write permissions by specifying we want to modify them for the group g plus add the permissions w for write. On our file example.txt, let's check the permissions. We see now for the group user, we have write permissions. We can subtract those permissions. Let's subtract the permit or revoke the permissions that I just gave to the group users, the write permissions and also revoke the write permissions for the group users and let's also revoke the read permissions. So the group users can no longer read nor write the file example.txt and at the same time, let's revoke the read permissions for other users. So we can combine different commands using the comma here. For other users, let's revoke, so subtract the read permissions on the file example.txt and let's check. We have now for the group user they have no permissions. Previously they had read and write permissions, but we revoked the read and write permissions and other users have no permissions. Previously they had read permissions. We revoked the read permission using the O minus R. So we can combine multiple permissions or permission operations for different sets of users and another example, we can add execute permissions. In this case, let's add them for the user owner for S Gordon using U to specify the owner, the user, add execute permissions, X for example.txt, ls minus l example.txt. We now see that the user S Gordon indicated by, because we use the minus of the U option, the user S Gordon now has execute permissions because we've added those execute permissions for the user owner. Using the change mod command. So we can add we can modify the permissions based on the user, the group, or other users. We can also modify the permissions for all users using the A to indicate all users. In this case, I want to set all users so that they can read the file. Just before I do that, just one thing to note on the this Linux terminal, when a file has execute permissions, as we added for the example.txt, it's shown in green in the file name list. That's not always the case, just in this terminal. Coming back, we want to add read permissions for all users. A for all users, plus to add permissions are for read permissions on example.txt. Let's check. The user owner has read permissions. They previously had read permissions. We've added read permissions for all users, so it simply doesn't modify. They still have read permissions. So S Gordon has read permissions. The group members have read permissions and other users also have read permissions. So change mod allows us to change the permissions on files and we can also do that on directories. And it can be quite complex in the combinations you can have. You need to be careful that you set the permissions to achieve the security goals that you're looking for on your system. It's not so obvious sometimes and in fact there are many more options that we will not go through in this demo. Let's clear the screen and now let's look at changing the owner of a file and changing the group owner of a file. Our file example.txt is owned by the user S Gordon and the group owner or the primary group associated with this file is the faculty group. First, let's change the group owner for this file. The command chgrp, change group, specify the group that we want to change it to. In this case, I know that there's a group its413 and the file name change the group of the file example.txt to its413. Let's look and check. We see now that the group owner is its413. So very simple to change the group for a file. What about changing the owner? Well, we need to be careful there that we need to have the right permissions to change the owner of a file. I'm going to switch to the instructor user for this demo. Burger has I know that the instructor user has administrator access on the system. I know their password. That is, as the instructor user I can execute commands using sudo. Let's look at the files. I'm logged in now as the instructor user. I switched to the instructor user using su. I'm still in the directory of slash home slash s Gordon. Still looking at the example.txt file. The owner is s Gordon. The group owner is its413. Let's change the owner to someone else and because I'm not the owner, I will proceed this with sudo because I need administrator access or root privileges to perform this operation. So sudo and to change an owner use chown, change owner, specify the new owner, it's currently owned by s Gordon. Let's change it to be owned by a different user. Smith, specify the username and the file. I'm prompted for the password for the instructor user to execute this command as sudo. I know the password for the instructor user. The command executes. Let's check. We now see the owner for example.txt is the user Smith. So we can change groups using chgrp, change group. We can change the owner, the user owner of a file using chown, change own. But we need to be careful that we don't always have permissions to change the owner and in some cases also the group owner of a file. And this example I use sudo because I knew I didn't have permissions to change the owner to Mr. Smith in this case. In fact, it turns out you can use the command chown to change both the owner and the group. So we don't need to use change group. We can combine and let's change the owner of the file example.txt back to s Gordon from Smith back to s Gordon and let's change the group back to faculty currently owned by Smith group ITS 413 I want to change it back to the original which was s Gordon group faculty and We can do all that with one command using chown s Gordon and we specify the group following by a dot Sorry followed by colon and the group that we want So now I'm changing two things the user owner and the group owner for this file chown the user I want to change the owner to and the group I want to change the file ownership to separated by the colon and Now we see that we have back to our original user s Gordon and the original group faculty So we don't actually need to use change group. We can use change own to do the group as well Look in the man page for those commands to see the different options They have in the different ways that you can combine the user and the group in in chown So in summary we can change permissions on files and directories using ch mod change modifications We can change the owner using ch own and we can change the group using ch g rp Or we can in fact and do it with ch own as well