Garden of KnowledgeApplied Sciences › Computer Science › Software › Security › Certifications › LFCS

q29-links-and-file-attributes

Énoncé§

Solve this question on: terminal

  1. Create a hard link /opt/course/29/hard-passwd pointing to /etc/passwd.
  2. Create a symbolic link /opt/course/29/soft-passwd pointing to /etc/passwd.
  3. Make /etc/resolv.conf immutable so even root cannot edit it without removing the attribute.
  4. Write the inode number of /etc/hostname into /opt/course/29/inode.

Solution§

sudo ln /etc/passwd /opt/course/29/hard-passwd
ls -li /etc/passwd /opt/course/29/hard-passwd
# both entries share the same inode and link count goes up

Hard link properties:

ln -s /etc/passwd /opt/course/29/soft-passwd
ls -l /opt/course/29/soft-passwd
# lrwxrwxrwx ... soft-passwd -> /etc/passwd

Symbolic link properties:

Useful flags:

Step 3 — File attributes with chattr§

sudo chattr +i /etc/resolv.conf       # immutable
lsattr /etc/resolv.conf
# ----i---------e----- /etc/resolv.conf
sudo chattr -i /etc/resolv.conf       # remove

Common attributes:

AttrMeaning
iimmutable — no edit, rename, delete, link
aappend-only — only appends, no rewrite/delete
Ano atime updates
ccompressed (filesystem dependent)
dexcluded from dump
eextent format (informational, ext4)
jdata journaling
ssecure deletion (zeroed on delete)
Ssynchronous writes
uundeletable — content kept after rm

Step 4 — Inode number§

stat -c %i /etc/hostname > /opt/course/29/inode
# or:
ls -i /etc/hostname | awk '{print $1}' > /opt/course/29/inode

Extended attributes (xattr)§

Separate from chattr; used by SELinux, ACLs, custom metadata:

getfattr -d -m '.*' file              # show all
setfattr -n user.note -v "hello" file
setfattr -x user.note file
—The Gardener