Default Permissions: umask

Where do 644 and 755 come from?

New files and directories get their permissions from the umask, a mask of the permissions to take away. Files start from 666 (no one gets x by default) and directories from 777; the umask is removed from that:

umask
touch new.txt
mkdir new-dir
ls -ld new.txt new-dir

In the terminal

student@vulntech:~$ umask
0022
student@vulntech:~$ touch new.txt
student@vulntech:~$ mkdir new-dir
student@vulntech:~$ ls -ld new.txt new-dir
drwxr-xr-x 2 student student 0 Oct 17 06:31 new-dir
-rw-r--r-- 1 student student 0 Oct 17 06:31 new.txt
Starts atminus umask 022Result
New file666022644 rw-r--r--
New directory777022755 rwxr-xr-x

A private umask

umask 077 takes everything away from the group and others, so all your new files are private:

umask 077
touch secret.txt
mkdir secret-dir
ls -ld secret.txt secret-dir

In the terminal

student@vulntech:~$ umask 077
student@vulntech:~$ touch secret.txt
student@vulntech:~$ mkdir secret-dir
student@vulntech:~$ ls -ld secret.txt secret-dir
drwx------ 2 student student 0 Oct 17 06:31 secret-dir
-rw------- 1 student student 0 Oct 17 06:31 secret.txt

The setting only lasts until you close the shell. To keep it, add the line umask 077 to your ~/.bashrc.

Remember: umask lists what's taken away from new files (666) and directories (777). 022 gives 644/755, 077 gives 600/700.

HOME LEARN COMMUNITY DASHBOARD
Practice terminal Starting…