Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

You can also use the octal form of the chmod command (for example, to
modify a file’s permissions so that only you, the owner, can read and write a
file). Use the chmod command and a file permission of 600 , like this:


Click here to view code image
matthew@seymour:~$ chmod 600 readme.txt
matthew@seymour:~$ ls -l readme.txt
-rw------- 1 matthew matthew 0 2015-06-30 13:33 readme.txt


If you take away execution permission for a directory, files might be hidden
inside and may not be listed or accessed by anyone else (except the root
operator, of course, who has access to any file on your system). By using
various combinations of permission settings, you can quickly and easily set
up a more secure environment, even as a normal user in your /home
directory.


File Permissions with umask


When you create a file, it is created with a default set of permissions. You can
view and modify the default permissions for files with umask, which works
like a filter. When a file is created by a user account, whether that account is
owned by a human like matthew or a process like init, the file will be
created using specific permissions.


The numbers we used above when discussing file permissions are also used
with umask, but with an interesting change. Now, the numbers defined in
umask are subtracted from the ultimate file permissions. So, if you wanted
all new files to be created with a default permission of 777 , you would type
this:


Click here to view code image
matthew@seymour:~$ umask 000


Of course, you would never want to have all your files accessible by default
because that would be incredibly insecure and unsafe. The default umask is
022 , which means that files are created by default with 755 permissions,
except in your /home directory where the umask is 002 and files are
created with 775.


To find the current umask setting, use this:


Click here to view code image
matthew@seymour:~$ umask


This may list four digits instead of three. If so, don’t be confused. The

Free download pdf