Skip to the page

Linux for operators · core

File permissions, ownership and SSH access

Permissions use owner, group and others with read, write and execute bits. SSH key login also checks file permissions, so a careless chmod can lock everyone out.

The notes

What you must know

  • Three sets (owner, group, others) of read (4), write (2) and execute (1). 755 is rwx for the owner and r-x for others. 640 is rw for the owner, r for the group and nothing for others.
  • On a directory, r lists names, w creates, deletes and renames entries, and x lets you enter it. Deleting a file needs write on the directory, not on the file.
  • umask removes bits from the default (666 for files, 777 for directories). umask 022 gives 644 and 755.
  • setuid runs a program as its owner. setgid on a directory makes new files inherit the group. The sticky bit (as on /tmp) lets only a file owner delete it.
  • Fix an unwritable uploads folder with the right owner or group, setgid and group write, not with chmod 777.
  • sshd with StrictModes yes (the default) refuses keys when the home directory, ~/.ssh or authorized_keys is writable by group or others. A chmod -R 775 on /home broke every key login.
  • ssh -vvv shows which keys were offered. Permission denied (publickey) means the server rejected the key and the network is fine.
  • Way back in without SSH on AWS: Systems Manager Session Manager, the EC2 Serial Console, or fixing the root volume from a rescue instance. Roll out SSH changes to a few hosts first and keep a tested second way in.

The red pen

Common traps: mistake → fix

  • Mistake: chmod 777 is a quick safe fix

    Fix: it gives write access to everyone.

  • Mistake: More open permissions never break anything

    Fix: SSH refuses keys if files are too open.

  • Mistake: Deleting a file needs write on the file

    Fix: it needs write on the directory.

Easy to hard

Questions interviewers ask, easy to hard

  1. What do 755 and 640 mean?
  2. What do setuid and the sticky bit do?
  3. The app cannot write to the uploads folder after a deploy. How do you fix it without 777?
  4. Nobody can SSH into 300 servers after a hardening script. What do you do?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview