CHAPTER 14 UNDERSTANDING LINUX FILES AND USERS (Web site layout)
CHAPTER 14 UNDERSTANDING LINUX FILES AND USERS You can see that the file is owned by root. Remember that in this example, you re logged in as keir and your group is keir. The list of permissions starts with a d, so you can tell that this is actually a directory. After this, you see that the owner of the directory, root, has permission to read, write, and access the directory. Next are the permissions for the group: three dashes. In other words, members of the group called root have no permission to access this directory in any way. They cannot browse it, create new files in it, or even access it. Following this are the permissions for the rest of the users. This includes you, because you re not the user root and don t belong to its group. The three dashes means you don t have permission to read, write, or access this directory. SWITCHING USERS If you have more than one user set up on your system, it s possible to switch users on the fly while you re working at the shell. On my test PC, I have an additional user account called frank. While logged in as any user, I can temporarily switch to this user by typing the following command, which stands for substitute user: su frank I ll then be asked for user frank s password. Once this is typed, I will effectively have logged in as user frank. Any files I create will be saved with frank s ownership. If you created a root account (by using the command sudo passwd root), you can temporarily switch into it by typing just su, without any username afterwards. To return to your own account from any other account, type exit. Altering Permissions You can easily change permissions of files and directories by using the chmod command. For example, if you want to change a file so that everyone on the system can read and write to it, type the following: chmod a+rw myfile In other words, you re adding add read and write (rw) permissions for all users (a). Here s another example: chmod a-w myfile This tells Linux that you want to take away (-) the ability of all users (a) to write (w) to the file. However, you want to leave the other permissions as they are. You can substitute a with g to change group permissions instead. The most useful use of chmod is in making a program file that you ve downloaded executable. Due to the way the Internet works, if you download a program to install on your computer, it can lose its executable status while in transit. In this case, issue the following command: chmod +x myprogram