Weight | 1 |
Description | Special directories and files on a Linux system including special permissions. |
Key Knowledge Areas:
◈ System files, libraries.
◈ Symbolic links.
The following is a partial list of the used files, terms and utilities:
◈ /etc, /var.
◈ /tmp, /var/tmp and Sticky Bit.
◈ ls -d.
◈ ln -s
Nice to know:
◈ Hard links.
◈ Setuid/Setgid.
Organization of the File System
The Linux file system is separated into directories that reflect the purpose of the files stored within that directory. The directory /etc is the server configuration directory, generally users can read but not write to files in this directory. In addition, even the user root would not need to make changes frequently to this directory. The directory /var, on the other hand, holds log files, print spool files and perhaps database files to this directory structure would be written to frequently but by services rather than users. The directory /tmp is used by all users and they will need write access to this directory.
Special Permissions
Users who can write to the directory can also delete files from the directory, to control deletions the special permission known as the sticky bit is assigned to the /tmp directory. When the sticky bit is set on a directory on the owner of the file can delete the file.
When the sticky bit is set it shows in the space for the execution permission in the others block, where the execute permission is also set then it will sow as a lowercase t, where execute is not set it will show as an uppercase t.
To set the permission using symbolic notation this can be set with chmod:
chmod o+t /tmp
The octal permissions would be 1777 for the /tmp directory, this can be seen with the stat command:
Special permissions also exist for the group and user block. These are known as the set UID and set GID permissions. When a file is set with these permissions, executing the file will result in the permissions granted to the user or the group are used, user permissions if the SUID bit is set, group permissions if the SGID bit is set. If we look at the executable file wall (/usr/bin/wall) we see the permissions show as rwxr-tr-x root tty ; anyone executing the file will do so as the group tty so access to terminals will be allowed.
The SGID bit may also be set on a directory and, in which case, it will effect the group ownership of all new files created in the directory ensuring that new files are group owned by the group owner of the directory
The SUID bit is set commonly on the the file /usr/bin/passwd so that users can change their own password and write to the /etc/shadow file that is writable on by root.
Hard Links
Hard links are files that have multiple names. A file name in Linux points to an inode, hard links are files inodes that have more than one file name linking to them. As such, hard links, do not take any extra disk space as there is no additional data used. File-systems also restrict the number of inodes that can be created and hard links do not create any extra data or inodes. Running ls -l or using the find command hard links will show as regular files, however from the output of ls -l we can view in the 2nd field how many names link to the inode; if it is more than 1 there are hard links to the file.
From the output above we can see the document.txt and hello.txt are hard links, not necessarily to each other but they both contain 2 names linked to the one inode entry in the file-system as highlighted.
Hard links are restricted to the same file-system and most file-systems do not support hard linking to directories and are less commonly used than soft links. To create a hard link use the command ln:
ln <target file> <link name>
ln document.txt hello.txt
The video will introduce to you inodes and what they are in the file-system and hard linking of files. Scrolling below the video we will start describing Soft Links:
Soft Links
Symbolics links are actual links and show as the file type link within the ls -l output and that of the command file. If directory colors are turned on then symlinks will show as light blue but with or without colors on you will see the first character in the output of ls -l for the symlink name is “l”. This denotes a link. This is different to hard links which are regular files. From the following screenshot we can see that the file fred.txt is linked to document.txt and shows as a file type of link, denoted by the 1st character on the output of ls -l being l instead of – for regular files and hard links.
Symlinks are very similar to Aliases in the MAC OS and Shortcuts in Windows as with their counterparts in other OSs, these are completely separate files in the file-system and so have their own name, inode and data. The data of the symlink points to the original or target file. With hard links they are inodes that have more than one file name linking to them. Symlinks are more flexible in that they can link across file-systems to different partitions and drives and link to directories. To create symlinks use the command:
ln -s <target> <linkname>
such as
ln -s /usr/share/doc ./doc
The example creates a link called doc in the current directory to the directory /usr/share/doc.
0 comments:
Post a Comment