>_ IzzyLab

Hands-on task

This task is step 15 of the course “Users, groups and permissions”

Move the keys without losing permissions

medium~7 min

The deploy keys from /root/keys have to be moved via an archive. Pack the directory into a compressed archive /root/keys.tar.gz, then extract it into /root/migrated so that the permissions are preserved: the keys directory is 700, id_deploy is 600, id_deploy.pub is 644.

What you'll practise:
  • tar
  • tar -z
  • preserving permissions
  • stat
  • moving secrets

Topic breakdown

A tar archive stores each file's metadata along with its content: access mode, owner, modification time. So moving files through an archive can preserve permissions — if you ask for it on extraction: the preserve-permissions flag applies the mode from the archive as is, without trimming it by the current session's umask. For private keys this is critical: SSH refuses to use a key accessible to anyone but its owner. -z passes the archive through gzip, and -C sets the directory the paths are relative to.

What's checked

  1. /root/keys.tar.gz is gzip-compressed and contains the keys
  2. directory /root/migrated/keys is 700
  3. key permissions preserved (600 and 644)

What it looks like