Restricted SSH keys for automated jobs
A job that runs without a person present cannot enter a 2FA code. It needs its own key, restricted to the command it runs and approved by support. Your normal login key stays as it is. For interactive reuse, see Reusing SSH connections (multiplexing).
What we can and cannot approve
We can't exempt a key that isn't restricted. An exempt key can't open a shell,
runs only its approved command, and, for rrsync, is confined to the approved
directory.
We may review the restricted entries in authorized_keys at any time without
notice. If an entry no longer matches the approved restriction, we may remove
the exemption.
Before you start
Complete enrollment in Two-Factor Authentication (2FA) and check that your interactive login works. You need access to the project's data and the address the job connects from.
Send and receive data through a data-mover rather than a login node. The
examples connect to data-mover03.hpc.swin.edu.au; see File Transfer
for the other data-movers.
Replace USER with your username, PROJECT with your project directory,
and SOURCE with the address the job connects from, or a range such as
203.0.113.0/24. Replace DIR1 through DIR4, and DIR, with your own
directories. These are placeholders, not directories that exist.
Step 1: Create a dedicated key
On the machine that runs the job, create a key for this job only:
ssh-keygen -t ed25519 -f ~/.ssh/automation -N '' -C unattended-job
cat ~/.ssh/automation.pub
The key has no passphrase, so it can run unattended. Choose a filename that
isn't already in use, and send support only the .pub file, not the private
key.
Step 3: Request the exemption
Email hpc-support@swin.edu.au with:
your username
the address the job connects from
the command or destination, including the restricted entry
the public key from the
.pubfile
An exemption applies to the approved key, not to every login on your account.
Step 4: Test it
Test from the machine and network that will run the job.
The key works before the exemption is approved, but 2FA still applies. Confirm the key is installed by logging in with it to the host the job uses; for an rsync job that is a data-mover:
ssh -i ~/.ssh/automation -o IdentitiesOnly=yes -o ControlPath=none USER@data-mover03.hpc.swin.edu.au
Enter your code when asked. Reaching the prompt means the key was accepted.
After the code, an rsync entry refuses with Not invoked via sshd and a
fixed-command entry prints its output. Either means the key works and only the
exemption is missing, which is the part an unattended job cannot supply.
Once the exemption is confirmed, the same connection runs without a code. Add
BatchMode=yes so a prompt cannot hide a failure, and check the job's command:
rsync -av --dry-run -e 'ssh -i ~/.ssh/automation -o IdentitiesOnly=yes -o BatchMode=yes -o ControlPath=none' USER@data-mover03.hpc.swin.edu.au:/fred/PROJECT/data/DIR/ dest/
For an upload, swap the arguments:
rsync -av --dry-run -e 'ssh -i ~/.ssh/automation -o IdentitiesOnly=yes -o BatchMode=yes -o ControlPath=none' local/ USER@data-mover03.hpc.swin.edu.au:/fred/PROJECT/incoming/
A fixed command runs on the host that job connects to, usually a login node:
ssh -i ~/.ssh/automation -o IdentitiesOnly=yes -o BatchMode=yes -o ControlPath=none USER@ozstar.swin.edu.au
The first two list files without copying. The last prints the fixed output and never a shell.
What the restriction does not do
from= limits where the key connects from, command= fixes what it runs,
and restrict turns off terminals and forwarding. These limit what someone
holding the key can do; they don't constrain you, since you control
authorized_keys. A write-only key can still overwrite files in its
destination.