CodePark/ questions / Linux commands & permissions
START PRACTICINGPRACTICE
Backend question · OS, networking & Linux › Linux commands & permissions

Explain Linux file permissions and what chmod 755, 644 and 600 mean. Which would you use for a script, a config file and an SSH private key?

Every file has an owner and a group. It has three sets of permissions:

  • one for the owner
  • one for the group
  • one for others (everyone else)

Each set adds up three numbers: read (4), write (2) and execute (1). Each digit in 755 is one of these sums, written in octal (base 8).

The three common values:

  • 755 is rwxr-xr-x. The owner can read, write and execute. Everyone else can read and execute. Use it for scripts, binaries and directories.
  • 644 is rw-r--r--. The owner can read and write. Everyone else can only read. Use it for config files and static assets.
  • 600 is rw-------. Only the owner can read or write. Use it for secrets like SSH private keys and .env files. ssh refuses to use a private key that other users can read.

On a directory, the letters mean different things:

  • r lets you list the names inside.
  • w lets you create and delete entries.
  • x lets you enter the directory and reach the files inside.

Use chmod to change permissions. Use chown user:group file to change who owns the file.

  • There are three permission sets: owner, group and others. Read is 4, write is 2 and execute is 1.
  • 755 (rwxr-xr-x) is for scripts and directories.
  • 644 (rw-r--r--) is for regular files and config files.
  • 600 (rw-------) is for secrets such as SSH keys.
  • On a directory, x means you can enter it and pass through it.