Wondering on ‘How umask works in Linux?’
File permission management is a frequent task in Linux systems.
And setting umask decides the default permissions of files. However, bad umask values create problems in file creation.
At Bobcares, we often get customer query on default file permissions and umask, as a part of our Server Management Services.
Today, let’s see how umask works in Linux from our Support Engineers and the proper way to set it.
What is umask?
Before getting into umask, let’s have a quick look at file permissions.
Permissions are important for ensuring file protection. In Linux, there are three classes of users. That is user, group and others.
Also, each of these user classes can have three types of file access. They are read, write and execute.
The umask command sets a mask that determines the default file permissions of newly created files. This is applicable for changing file permissions too.
How to setup umask in Linux?
Now let’s see how our Support Engineers set umask in Linux?
The basic umask command is, umask [-S] [mask]
To display the current mask simply use the command, umask
The -S option displays the file permission symbolically.
For the systemwide umask setup, firstly we create a file.
vi /etc/profile
Now we add the mask as,
umask xxx
Here xxx is the umask value. Usually, we set the umask value as 022. The base permissions of folders are 777 and files are 666 in a system. The 022 umask value set this to 755 and 644 respectively.
Finally, save the file.
The umask values on a server appear as :
Errors due to umask in Linux
Now let’s see common errors due to incorrect umask value in the server.
1. Misconception about umask
Some users assume that umask is the same as chmod command. But this is completely opposite of umask.
In this case, our Support Engineers give proper insight into umask. Umask masks the given value from the base permission.
That is, if the customer needs to provide 755 for the directory, then give the umask of 022.
2. Change of permission after the file transfer
Recently, one of our customers had an error while transferring files using SFTP. The preserved file permission changed after a remote file transfer.
And the customer had to reset the file permission every time with the chmod command.
On further debugging, our Support Engineers found that the error was with the umask value. Finally, we changed the umask value to fix the error.
[Still having any troubles on file permissions? – We’ll help you.]
Conclusion
So far, we saw how umask works in Linux. Today, we had a quick look on umask and file permissions in Linux. We also saw how our Support Engineers fix umask related errors.
0 Comments