I need two suggestions for making my script working from local server as well as ssh execution
1. How to update the sudoers
In server i have a path
/var/log/data/status/
all files of parent and child_dir are owned by tomcat user and group.
-rw-rw-r-- 1 tomcat tomcat 0 Feb 17 02:23 20221119.status
-rw-rw-r-- 1 tomcat tomcat 0 Feb 17 02:23 20221116.status
-rw-rw-r-- 1 tomcat tomcat 0 Feb 17 02:23 20221112.status
I want user named new_user to able to rename the files under the /var/log/data/status/ as part of my script. I have tried to edit my sudoers file like below but it to run without password because tomcat is application user does not have password, Unsure how to make sudoers changes for it.
new_user ALL=NOPASSWD: /bin/bash /path/my_script [a-z_]* 20[0-9]*
what i want to achieve is, to run without any password
sudo -u new_user /bin/bash /path/my_script
2. Run the script over ssh
My another requirement is to run the same script from other server over ssh, if possible, please help with the syntax
- On server A (Login as my user iamsage) -
i need to run something like this
ssh new_user@remote_host "sudo -u new_user /path/my_script arg1 arg2"
sudo su - new_user /bin/bash /path/my_script
instead ofsudo -u new_user /path/my_script arg1 arg2
? Please edit your question to add requested information.sudo su
, your question body talks aboutsudo -u -
, and I guess what you actually want issudo -u
(with no extra-
). Also, please clarify what you need to run: who runs the script? How? What command? Cannew_user
ssh into the machine? Can't you just dossh new_user@ip /path/my_script arg1 arg2
?{{/var/log/data/status/<some_files}}
is possible as a path, but it's quite unusual, and a path like that is unlikely to help when you're struggling with something else.-
insudo -u - new_user ...
? Did you run the command? Copy&paste the command you run on your system and the resulting output or error message. Yourssh
command lacks the host name. It does not make sense to usesudo -u new_user
when your process is already running asnew_user
byssh new_user@host ...
There might be more misunderstanding in the question. Please explain what users are involved.sudo su - new_user ...
orsudo -u new_user ...
allow some other user to run a command as new_user. You might neednew_user
to run a command as user or grouptomcat
.