plink, Task Scheduler and safe unattended keys
plink — run a command over SSH from a batch file
plink -batch -load lab "df -h / ; systemctl is-active nginx"
-load labuses your saved PuTTY session (host, user, key).-batchnever stops to ask a question — it fails instead, which is what a script needs.- Save output:
plink -batch -load lab "uptime" >> C:\work\uptime.txt. - The PowerShell equivalent with OpenSSH:
ssh -o BatchMode=yes lab "uptime".
Schedule it
schtasks /create /tn "Lab nightly sync" /tr "C:\work\backup.bat" /sc daily /st 02:00
Or in the Task Scheduler GUI: Create Task → Triggers → Daily 02:00 → Actions → Start a program → backup.bat. Tick Run whether user is logged on or not only if the job uses a key that does not need Pageant.
A restricted key for unattended jobs
Make a second key without a passphrase just for the job, and limit what it can do on the server by putting options in front of it in authorized_keys:
from="198.51.100.25",restrict,command="/usr/local/bin/backup-only.sh" ssh-ed25519 AAAA... nightly-job@office-pc
from=— only accepted from your office IP.restrict— no port forwarding, no agent, no terminal.command=— whatever the client asks, only this script runs.
For SFTP-only jobs the admin uses a Match User block with ForceCommand internal-sftp instead of command=.
Try it — scheduled check
- Write
check.batthat runsplink -batch -load lab "uptime"and appends to a file. - Schedule it every 15 minutes for an hour.
- Read the file — four lines with the time.
Rating
0
0
There are no comments for now.
Join this Course
to be the first to leave a comment.