Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preserve sudo environment [duplicate]

Tags:

ssh

sudo

I'm trying to execute a script from a different server using ssh

Here's the command I'm using from server 1 to launch a query on server 2:

ssh -t [email protected] "cd /var/www/vhosts/xxxxx/subdomains/preprod/; sudo ./replace.sh";

but the problem is that when I do sudo the $home = /root while the script is under: /var/www/vhosts/xxxxx/subdomains/preprod/

How can i tell sudo to preserve the environment?

I tried sudo -P - , sudo -H, without any luck.

like image 267
Tarek Avatar asked May 05 '11 19:05

Tarek


1 Answers

That's what I got from the man page.

sudo -E

-E The -E (preserve environment) option will override the env_reset option in sudoers(5)). It is only available when either the matching command has the SETENV tag or the setenv option is set in sudoers(5).

like image 158
Tommy Avatar answered Dec 16 '22 20:12

Tommy