Preserve sudo environment [duplicate] - ssh

This question already has answers here:
Why does sudo change the PATH? [closed]
(18 answers)
Closed 3 years ago.
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 user#xxx.xxx.xxx.xx "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.

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).

Related

How to ban IP addresses requesting specific directory using apache [duplicate]

This question already has answers here:
Apache 2.4.x ip blacklist
(2 answers)
Closed 2 years ago.
Hello I'd like to permenently ban anything requesting the directory "/backups/" now how can I do that using a PHP script or mod_security?
I want to do this in a similar manner as iptables does this if possible.
I figured out how to do this on my own.
create a script in /bin called "blockip" containing the following
if [ -z "$1" ]
then
echo "No argument supplied"
exit 1
fi
echo "Blocking IP address $1"
iptables -A INPUT -s $1 -j DROP
then
chmod +x /bin/blockip
and now run
sudo visudo
add this:
nobody ALL = NOPASSWD: /your/script
make sure it is chmod 755
and add this code to index.php in the directory.
exec("sudo blockip ".escapeshellcmd($_SERVER['REMOTE_ADDR']));

why "systemctl" not working in Ubuntu terminal on Windows? [duplicate]

This question already has an answer here:
Enable Systemd in WSL 2
(1 answer)
Closed 2 months ago.
I need to reload the daemon using systemctl command in ubuntu terminal on window 10. I attached the error I received.
The error:
bashdos#yana:~$ systemctl
System has not been booted with systemd as init system (PID 1). Can't operate.
WSL doesn't have systemd implemented therefore in Ubuntu you need to run for example service start ssh or you can call the binary directly such as /etc/init.d/ssh start/stop/restart.
I had this problem running WSL 2
the solution was the command
$ sudo dockerd
Open other terminal and try it
$ docker ps -a
if after that you still have a problem with permission, run the command:
$ sudo usermod -aG docker your-user

How do I set php to start on reboot?

I am using Kirby on Ubuntu 16.04, and every time I reboot I have to login on my server, go to my website folder and type
sudo php -S 0.0.0.0:80
for the server to start.
What's a correct way of getting this to start automatically after a reboot?
Sorry for the trivial question, I just don't seem to be able to find a simple answer on the web...
You can use root's crontab with #reboot directive. Edit it with sudo crontab -e
#reboot cd /path/to/directory && php -S 0.0.0.0:80
Notice that there is no sudo before the php command, because it's run from root's crontab.

Removing Odoo 9 from Ubuntu 14.04 desktop? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I want to uninstall Odoo 9 and reinstall in my linux system. Can anyone please help me?
Just follow these steps
service odoo-server stop
Remove config file(s)
rm -f /etc/odoo-server.conf
rm -f /etc/odoo.conf
Remove application code
rm -R /opt/odoo
Remove startup process
update-rc.d -f odoo-server remove
rm -f /etc/init.d/odoo-server
Remove logs
rm -R /var/log/odoo
Remove databases
sudo service postgresql stop
apt-get remove postgresql -y
apt-get --purge remove postgresql\* -y
rm -r -f /etc/postgresql/
rm -r -f /etc/postgresql-common/
rm -r -f /var/lib/postgresql/
Delete users and groups
userdel -r postgres
groupdel postgres
To Remove postgre
find the file pg_hba.conf - it may be located, for example in /etc/postgresql-9.1/pg_hba.conf.
cd /etc/postgresql-9.1/
Back it up
cp pg_hba.conf pg_hba.conf-backup
place the following line (as either the first uncommented line, or as the only one):
local all all trust
restart your PostgreSQL server (e.g., on Linux:)
sudo /etc/init.d/postgresql restart
you can now connect as any user. Connect as the superuser postgres (note, the superuser name may be different in your installation. In some systems it is called pgsql, for example.)
psql -U postgres
Reset password
ALTER USER my_user_name with password 'my_secure_password';
Restore the old pg_hba.conf as it is very dangerous to keep around
cp pg_hba.conf-backup pg_hba.conf
restart the server, in order to run with the safe pg_hba.conf
sudo /etc/init.d/postgresql restart

Multiple commands using batch and Plink? [duplicate]

This question already has an answer here:
Use Plink to execute command (Oracle SQL query) on remote server over SSH
(1 answer)
Closed 3 years ago.
Hello I am trying to use a batch file to log into a server using plink, go to specific directory and run commands. I can not get this to work. Appreciate any help.
plink -t -ssh root#111.111.111.111 -pw xxxxx
cd /home/wonderd/public_html/dev.xxxx.com
./shell/indexer.php --reindex catalog_product_price
First I think you have to write the machine name or IP after the plink call
The second issue is that plink run always from root directory so you have to send couple commands together separated by ;
like this :
plink.exe <full name of machine / IP> "command one; command 2"
Try:
plink root#192.168.0.1 -pw xxxx (cd /home/path to script ; ./script.sh)