Hi, everyone.
I am trying to run a script as root using /etc/crontab.
Code:
X Y * * * root /some-path/script.sh
The first part of the script needs local root priviledges and runs fine.
The other half needs a regular user priviledges, but the job is run by user root in crontab and it fails.
Basically, the second part of the script is trying to access a remote directory using a regular user's credentials (keyfiles), not the root's ones. That is because the root doesn't have keyfiles on the local or on the remote host. The user test does have remote access to that host however, but only when ssh and rsync are run by user test (non sudo command).
So a command like
Code:
"ssh test@remotehost"
works just fine.
However, the script fails when it tries to execute these two commands:
Code:
sudo ssh -fnx4 -l test -i /home/test/.ssh/id_rsa.pub test@remotehost "mkdir /home/test/somedirectory"
This actually asks me the passphrase for the public key...
Code:
Enter passphrase for key '/home/test/.ssh/id_rsa.pub':
And there is no password for the public key...
The second command is this:
Code:
sudo rsync -avzl -e "ssh -l test" /home/test/Desktop/somefile test@remotehost:/home/test/somedirectory
And the output is "Permission denied (publickey).
Adding "-i /path/to/public_keyfile" leads to the same output as when using ssh:
Code:
Enter passphrase for key '/home/test/.ssh/id_rsa.pub':
Is it possible to make ssh and rsync login using another user credentials when they are started with root privileges by sudo?
Thank you.
Bookmarks