SSH Key for scp in Cron Script

Hello,

to pull some files from another server regularly, I want to use the scp command and a SSH key.

Could you give me a hint, please, how I can generate a SSH key pair in SCALE and use it for a command in my Cron Job or inside a script that is called by the Cron Job?

The only place I found to generateSSH key pairs is “Credentials → Backup Credentials → SSH Keypairs”.
Is this the correct place?

But how can I use such key inside my Cron Job?
How is the user that runs the Cron stuff connected to the right key in SCALE?

Or is my understanding somehow wrong?
Could you give me some hints on how I could realize the periodical pulling of files from another server via scp and SSH key via a Cron Job?

Thanks a lot in advance,

Thomas

Is there a reason you can’t use ZFS replication for this purpose instead? Because that’s something you can set up entirely through the GUI. Otherwise, if you really want to go the scp route, you’d need to script it and call the script via a cron job. And key management and everything else would be the job of the script.

Hi,
the other system does not have ZFS, therefore, I want to simply use scp for the job.
Is it possible to create at least the SSH key via the GUI and use the key in the script?

I don’t think it is, nor do I see why you’d want to. This is going to be a CLI-focused process; the only GUI involvement is going to be scheduling the cron job.

1 Like

You can do this from the UI. Is the target system a linux system? I generally set up a seperate rsync user on both systems and add keys via shell, then use the GUI to configure all of the jobs:

Found on the internet:

Generate an ssh key:

ssh-keygen -t rsa -b 4096 -C "comment"

copy it to your remote server:

ssh-copy-id user@ip

or you can manually append the ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys:

ssh user@ip 'mkdir ~/.ssh'
ssh user@ip 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub
1 Like