[Linux-Biella] ssh via user www-data on apache

Federico Pistono federicopistono a gmail.com
Ven 3 Dic 2010 11:06:53 CET


>mi ripeti cosa vuoi/devi fare?
>qualcosa del tipo: "clicco su una pagina web e mi parte uno script che fa scp?"

Yes.

>in questo caso: come lo lanci lo script?

$cmd="/usr/local/bin/ffencall.sh bla bla";
shell_exec($cmd);

> Allora, ti crei un utente per eseguire lo script che abbia i permessi
> necessari a leggere i dati di cui fare un rsync, diciamo l'utente pippi (che
> fantasia :D ), nella sua home metti poi lo script da eseguire, diciamo sync.pl
> La riga da mettere in /etc/sudoers dovrebbe essere una cosa del tipo
>
> www-data  ALL = (pippo) NOPASSWD:/home/pippo/sync.pl
>
> Ovviamente la chiamata sara'
> sudo -u pippo /home/pippo/sync.pl

Fatto. Se  eseguo da shell:

syncdata a mgds $ scp -v -i /home/syncdata/.ssh/id_dsa file.txt
fede a 192.168.0.102:/tmp/

Funziona. Vado in un'altra shell, eseguo:

www-data a mgds $ sudo -u syncdata scp -v -i /home/syncdata/.ssh/id_dsa
file.txt fede a 192.168.0.102:/tmp/

A un certo punto mi dice:
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/home/syncdata/.ssh/id_dsa':

I mio guess è che lui carica l'agent ssh quando carica il bashrc dell'utente:

syncdata a mgds $ cat /home/syncdata/.bashrc

SSH_ENV="$HOME/.ssh/environment"

function start_agent {
     echo "Initialising new SSH agent..."
     /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
     echo succeeded
     chmod 600 "${SSH_ENV}"
     . "${SSH_ENV}" > /dev/null
     /usr/bin/ssh-add;
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
     . "${SSH_ENV}" > /dev/null
     #ps ${SSH_AGENT_PID} doesn't work under cywgin
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
         start_agent;
     }
else
     start_agent;
fi

Ma se www-data lancia uno script come sycndata tramite sudo, il bashrc
non viene caricato, quindi l'agent non è su, quindi chiede la
passphrase, quindi da errore, come prima :(


Maggiori informazioni sulla lista Linux