[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: cron, sshfs and sudo




On 17/06/16 04:01, Wim Bertels wrote:

> Hallo,

Hello, Win.

> use case: use cron to mount a sshfs share (with automatic key auth)
> 
> on 1 installation this is working fine:
> script:
> "
> #!/bin/bash
> 
> sudo -u user1 sshfs user1@123.234.1.2:/var/user1/shared /mnt/shared
> 
> exit
> "
> 
> on the other it keeps failing because the passphrase needs to be entered
> to unlock the key, it doesn't fail however without sudo and a custom
> user1 crontab entry; but as cron is run by root, this should be able to
> do easier
> 
> suggestions?

One possibility I can think is to generate a public/private key pair for
the "user1" and copy the public key to 123.234.1.2.

Then install keychain (aptitude install keychain), adding the following
lines to the profile of user1:

keychain ~/.ssh/id_dsa
. ~/.keychain/$HOSTNAME-sh

Finally, in the mounting script, be sure to add the following line
before mounting itself:

source $HOME/.keychain/${HOSTNAME}-sh


I hope this will help.

Kind regards,
Daniel

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: