Day 3 of 5
⏱ ~60 minutes
Linux in 5 Days — Day 3

Permissions and Users

Understand rwx permissions, change them with chmod, change ownership with chown, and understand sudo.

Reading Permissions

ls -la output
-rwxr-xr--  1 bo  staff  1234 Apr 10 script.sh
│└──┬──┘└──┬──┘└──┬──┘
│   │      │      └─── others: read only (r--)
│   │      └────────── group: read+execute (r-x)
│   └───────────────── owner: read+write+execute (rwx)
└───────────────────── file type: - = file, d = directory
chmod: Change Permissions
# Symbolic mode
chmod +x script.sh     # add execute for everyone
chmod -w file.txt      # remove write for everyone
chmod u+x script.sh    # add execute for owner only
chmod go-w file.txt    # remove write from group and others

# Octal mode (more common in practice)
chmod 755 script.sh    # rwxr-xr-x (owner all, others read/exec)
chmod 644 file.txt     # rw-r--r-- (owner rw, others read)
chmod 600 secret.key   # rw------- (owner only)
chmod 700 private_dir/ # rwx------ (owner only)
chown and sudo
# Change owner
chown bo file.txt
chown bo:staff file.txt  # owner:group
chown -R bo ./mydir/     # recursive

# sudo: run as root
sudo apt install nginx
sudo systemctl restart nginx
sudo nano /etc/nginx/nginx.conf

# Switch to root (avoid where possible)
sudo -i

# See who has sudo access
cat /etc/sudoers
💡
Permissions 755 for directories, 644 for files, 600 for secrets. This is the pattern you'll use 90% of the time. 755 = owner can do anything, everyone else can read and traverse. 600 = owner only, no one else.
📝 Day 3 Exercise
Fix Permission Problems
  1. C
  2. r
  3. e
  4. a
  5. t
  6. e
  7. a
  8. s
  9. c
  10. r
  11. i
  12. p
  13. t
  14. .
  15. s
  16. h
  17. .
  18. T
  19. r
  20. y
  21. r
  22. u
  23. n
  24. n
  25. i
  26. n
  27. g
  28. i
  29. t
  30. w
  31. i
  32. t
  33. h
  34. o
  35. u
  36. t
  37. e
  38. x
  39. e
  40. c
  41. u
  42. t
  43. e
  44. p
  45. e
  46. r
  47. m
  48. i
  49. s
  50. s
  51. i
  52. o
  53. n
  54. .
  55. A
  56. d
  57. d
  58. e
  59. x
  60. e
  61. c
  62. u
  63. t
  64. e
  65. p
  66. e
  67. r
  68. m
  69. i
  70. s
  71. s
  72. i
  73. o
  74. n
  75. .
  76. C
  77. r
  78. e
  79. a
  80. t
  81. e
  82. a
  83. f
  84. i
  85. l
  86. e
  87. r
  88. e
  89. a
  90. d
  91. a
  92. b
  93. l
  94. e
  95. o
  96. n
  97. l
  98. y
  99. b
  100. y
  101. o
  102. w
  103. n
  104. e
  105. r
  106. .
  107. V
  108. e
  109. r
  110. i
  111. f
  112. y
  113. o
  114. t
  115. h
  116. e
  117. r
  118. s
  119. c
  120. a
  121. n
  122. '
  123. t
  124. r
  125. e
  126. a
  127. d
  128. i
  129. t
  130. .
  131. P
  132. r
  133. a
  134. c
  135. t
  136. i
  137. c
  138. e
  139. c
  140. h
  141. o
  142. w
  143. n
  144. t
  145. o
  146. c
  147. h
  148. a
  149. n
  150. g
  151. e
  152. o
  153. w
  154. n
  155. e
  156. r
  157. s
  158. h
  159. i
  160. p
  161. .

Day 3 Summary

  • Permissions: read (4), write (2), execute (1). Three sets: owner, group, others.
  • chmod 755 = rwxr-xr-x. chmod 644 = rw-r--r--. chmod 600 = private.
  • sudo runs one command as root. sudo -i opens a root shell.
  • SSH keys should be 600. Directories in .ssh should be 700. Git will complain otherwise.
Finished this lesson?