Discussion:
scp in crontab problem
(too old to reply)
Marcus Park
2024-09-13 12:40:02 UTC
Permalink
Hi list,

I have put the private key into my debian VPS (in ~/.ssh/ dir).

When I scp a file from this VPS to another one by hand without password,
it works.

But when I put this scp into crontab, it seems not work. The scp in
crontab via private key didn't run as I expect, nothing was copied to peer.

Can you help?

Thank you.
Marcus
basti
2024-09-13 12:50:01 UTC
Permalink
Post by Marcus Park
Hi list,
I have put the private key into my debian VPS (in ~/.ssh/ dir).
When I scp a file from this VPS to another one by hand without password,
it works.
But when I put this scp into crontab, it seems not work. The scp in
crontab via private key didn't run as I expect, nothing was copied to peer.
Can you help?
Thank you.
Marcus
Cron doesn't know anything about your environment variables.
You can set PATH or HOME or use absolute paths.

/usr/bin/scp -i /home/userYX/.ssh/myKEY ***@example.com ...

Best regards,
Marcus Park
2024-09-13 22:30:01 UTC
Permalink
updated: it's really due to environment issue, after I add the '-i' path
to scp, jobs run well now.

Thanks basti.

Greg Wooledge
2024-09-13 13:00:01 UTC
Permalink
Post by Marcus Park
I have put the private key into my debian VPS (in ~/.ssh/ dir).
Does this private key have a passphrase?
Post by Marcus Park
When I scp a file from this VPS to another one by hand without password, it
works.
But when I put this scp into crontab, it seems not work. The scp in crontab
via private key didn't run as I expect, nothing was copied to peer.
First question: what did the output say? Any output from the cron job
should have been mailed to you. If you don't have a mail reader set up
on this machine, try "less /var/mail/$LOGNAME" or something. If you
don't have local mail delivery set up, fix that.

Second question: if the key has a passphrase, are you using an ssh-agent
to invoke it normally? The cron job won't have access to your ssh-agent,
not without a bunch of additional setup.

For automated jobs, you usually need the private key to NOT have a
passphrase. And yes, this is a large security concern. You'll have
to balance your security needs against your application needs.
Charles Curley
2024-09-13 13:20:01 UTC
Permalink
On Fri, 13 Sep 2024 20:24:51 +0800
Post by Marcus Park
Hi list,
I have put the private key into my debian VPS (in ~/.ssh/ dir).
The private key of what?

And to ~/.ssh/ on which computer. you are talking about transferring a
file from one computer to another; which one?

And why the private key? Usually one transfers the public key from
one's own computer to another, and one keeps the private key, well,
private.
Post by Marcus Park
When I scp a file from this VPS to another one by hand without
password, it works.
But when I put this scp into crontab, it seems not work. The scp in
crontab via private key didn't run as I expect, nothing was copied to peer.
Don't tell us what you did, show us. Copy exactly the line(s) from your
crontab file and paste it into your email.

Did you get an email from cron? If so, show us that.
Post by Marcus Park
Can you help?
Not without better information.
--
Does anybody read signatures any more?

https://charlescurley.com
https://charlescurley.com/blog/
Loading...