File System Permissions
In this section we will go over the basic linux file system and permissions.
Filesystem¶
Everything in linux is a file including your devices. There are many top level folders but we will go over the most common ones and what they are used for. The start of the file system is / or also called root.
File system information
/
├── bin This is a directory to store user binaries. In many systems it is symlinked to /usr/bin
├── boot This directory stores files to boot your system. It is usually its on partition.
├── dev This directory stores information about devices on the system.
├── etc This is the main directory to configure a system. It stands for extended text configuration.
├── home This is usually where home directories for users are.
├── lib This is where libraries are stored
├── lib64 This is where 64 bit libraries are stored
├── media This is where external drives are mounted (usually on desktop systems)
├── mnt This is where things get mounted temporarily.
├── opt This is for optional software
├── proc This is for information about the system.
├── root This is a special home directory for the root account
├── run This stores information about running processes
├── sbin This stores system binaries usually requires root privileges to execute.
├── tmp Place where temporary files are stored.
├── usr This stores user data, binaries and libraries
└── var This stores variable data in a system, like database files or files for a web application.
Hard and Soft links¶
Often times files need to be referenced by a different name or from a different location. This is done with hard and soft links. Each have there advantage.
Hard Link¶
A hard link refers to the same location(inode) on the disk as the original file. If the original file is deleted, the hardlink is still valid. The hardlink has to be in the same filesystem. Hardlinks are faster than soft links because it does not have to resolve file names.
You create a hardlink with the ln command. Example of this would be ln oldfile newfile
Soft link¶
These tend to be more common than softlinks. They are slower because it has to do path resolution. Think of this as a shortcut to the original file. This means it has a different location on the disk(inode). These can cross the filesystem boundary. To create a softlink you still use the ln command but with the -s switch. Example of this would be ln -s oldfile newfile
Permissions¶
Linxu file permissions can be represent in a couple of different ways. The easier way to read is rwx. Each file has 3 places for that, user, group, and other. If you look at a ls -al the first part of each line is the permissions the first character represents whether its a directory or link. The next 3 position correspond to read write and execute for the user. The next 3 positions are for group, and the last 3 are for other.
A like like above would mean the user has read, write, and execute privledges. Both the group and other only have read permissions.
Another very common way to look at permissions is in there octal format. To use this method you have 3 digits. Each digit represents user, group, or owner. Read is 4, write is 2, and execute is 1. So the above line in octal format is 744. 755 would be -rwxr-xr-x. 766 would be -rwxrw-rw.
Changing permissions¶
Changing permissions is done with the chmod command. It takes the format of chmod permission file.
Permission can be specified a couple of different ways. The most common way is in octal format chmod 644 file. Another way is to specify u for user, g for group, or o for other then the + or - sign and the the permissions you are wanting to change. So you could do chmod ugo+rwx file which would give user,group, and other read,write,and execute privileges or 777.
You may not have writes to change permissions on a file as your user. In this case you will need to escalate to root with sudo if your account has sudo privileges. To run any command you would preface it with sudo. We will go into sudo in more detail in the User Management section.
Changing owner and groups on files¶
To change the owner of a file you can use the chown command. chown can also changes the group of a file. To change just the owner you can use chown user file. To change the user and group its chown user:group file. To change just the group its chown :group file.
Another option if you only need to change the group is to use the chgrp command. its format is chgrp group file.
chown and chgrp examples
Exercise¶
Note
On AWX https://tower.tuckhome.lan use the Filesystem Permissions - Setup, Filesystem Permissions - Grade, Filesystem Permissions - Cleanup.
Tasks¶
- Create a hardlink named hardlink that points to file linkfile
- Create a softlink named softlink that points to file linkfile
- Set permissions on permfile so that the owner has read, write, and execute, and that group has read and write, and other has read.
- Change the owner of file ownerfile to student
- Chagne the group of file groupfile to student
- Change the group and owner of file groupandownerfile to student for the owner, and student for the group
Solution
- Create a hardlink named hardlink that points to file linkfile
- Create a softlink named softlink that points to file linkfile
- Set permissions on permfile so that the owner has read, write, and execute, and that group has read and write, and other has read.
- Option 1 using the ugo method combined
- Option 2 using ugo method individually
- Option 3 use octal format
- Change the owner of file ownerfile to student
- Chagne the group of file groupfile to student
- Option 1 using chgrp
- Option 2 using chown
- Change the group and owner of file groupandownerfile to student for the owner, and student for the group