Hi, First post, relatively long freenas/truenas user.
Issue: Cannot automate (via CRON Tasks) script running rsync to connect to remote host using a users SSH key
FreeNAS-11.3-U5 => TrueNAS-12.0-U5.1
Error on Truenas side '/var/log/messages'
Background:
User: userA created via GUI. SSH key generated (Freenas) via command line. Inserted public key into remote site (truenas) via GUI (Accounts => Users => Authentication box)
SSH password-less connectivity works via command line
i.e.
NOTE: I also use ~/.ssh/config to auto configure a port number since I user NAT/port translation on the remote/receiving end.
Running this script via $userA CLI works. Files are moved across SSH keys are working so ALL GOOD!
Now, automating this script to run via CRON
Using Freenas GUI : Tasks => Cron Jobs
This is set in the GUI to run daily. When this CRON is triggered the error on the remote host is received
"error: kex_exchange_identification: Connection closed by remote host"
So:
NOTE: I am using RSYNC module for other tasks between local servers (also Freenas => Freenas).
I do not use RYSNC module for the task in question because I need a 'kill' script' to trigger every morning and not clog the pipe. Sometimes GB/TB are pushed through so this scripts allows control of when the task starts/stops.
Any pointers appreciated. I have read about 'env' and that cron has different env so I assume it's something along those lines.
askubuntu.com
Summary:
- Script created to run multiple RSYNC tasks over a different port via SSH keys
- CLI works
- Cron does not
Cheers
Issue: Cannot automate (via CRON Tasks) script running rsync to connect to remote host using a users SSH key
FreeNAS-11.3-U5 => TrueNAS-12.0-U5.1
Error on Truenas side '/var/log/messages'
error: kex_exchange_identification: Connection closed by remote host
Background:
User: userA created via GUI. SSH key generated (Freenas) via command line. Inserted public key into remote site (truenas) via GUI (Accounts => Users => Authentication box)
SSH password-less connectivity works via command line
i.e.
- login to Freenas (putty) as userA
- #ssh <remotehost>
- Success! connected to host
Code:
rsync -av -zz --delete /mnt/DiskPoolB/userA/loc1 userA@$REMOTESERVER:/mnt/tank/loc1 rsync -av -zz --delete /mnt/DiskPoolB/userA/loc2 userA@$REMOTESERVER:/mnt/tank/loc2 rsync -av -zz --delete /mnt/DiskPoolB/userA/loc3 userA@$REMOTESERVER:/mnt/tank/loc3
NOTE: I also use ~/.ssh/config to auto configure a port number since I user NAT/port translation on the remote/receiving end.
Code:
Host remote.hostname.com Port 8022 IdentityFile /mnt/DiskPoolB/userA/.ssh/id_rsa
Running this script via $userA CLI works. Files are moved across SSH keys are working so ALL GOOD!
Now, automating this script to run via CRON
Using Freenas GUI : Tasks => Cron Jobs
Code:
/mnt/DiskPoolB/userA/backup-remote.sh >> /var/log/backup_remote.log
This is set in the GUI to run daily. When this CRON is triggered the error on the remote host is received
"error: kex_exchange_identification: Connection closed by remote host"
So:
- Which user does cron run as?
- When looking at #crontab -l as root, empty
- When looking at $crontab -l as userA, empty
- I have specified the identity file in ~/.ssh/config --- Is this not used when cron is running?
NOTE: I am using RSYNC module for other tasks between local servers (also Freenas => Freenas).
I do not use RYSNC module for the task in question because I need a 'kill' script' to trigger every morning and not clog the pipe. Sometimes GB/TB are pushed through so this scripts allows control of when the task starts/stops.
Any pointers appreciated. I have read about 'env' and that cron has different env so I assume it's something along those lines.

Why crontab scripts are not working?
Often, crontab scripts are not executed on schedule or as expected. There are numerous reasons for that: wrong crontab notation permissions problem environment variables This community wiki aims to
Summary:
- Script created to run multiple RSYNC tasks over a different port via SSH keys
- CLI works
- Cron does not
Cheers