I need to read the crontab file of a shared user on a remote machine.

I cannot SSH directly to that user, but rather SSH to my private user and then run sudo -iu <shared user>, so I can't directly run crontab -l.
I have an SFTP connection to that user on the remote machine, but I can't read /var/spool/cron/<user> directly, due to lack of permissions for the directory /var/spool/cron (it seems that the crontab executable can get the permissions to that file because it has the setuid bit set).
SSH-ing to my user, then switching to the shared user and running crontab -l is not optimal.

Is there any other way to achieve this?

  • 1
    Did you try something like ssh -t user@server sudo -u shareduser crontab -l (as a single command)? – Kusalananda Jun 5 '18 at 14:57
  • As I mentioned in the line before last, doing this is not optimal. The problem is not with the number of commands, but rather with the method: it requires a personal user's credentials in production code. – ezer1337 Jun 6 '18 at 15:05
  • Then set up a dedicated user account for doing this. – Kusalananda Jun 6 '18 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.