Running scripts as a different user without password

0 votes

I have a shell script that I need to run as another user, but, it can only be executed by the current user in my app. I want to execute something like this:

su user2 -C script.sh

But, how can I run this without having to type the password. Say the current user is user1 and the other user is user2. So, I need something which only lets user1 execute the script under user2 and nothing else.

I've tried changing my sudoers file but to no avail. Is there anything that I can do here with which I can accomplish this?

Jul 3, 2019 in Linux Administration by ffdfd
• 5,550 points
2,234 views

1 answer to this question.

0 votes

You'll have to edit you sudoers file only. Use visudo command and then add this to the file:

user1 ALL=(user2) NOPASSWD: /home/user2/bin/test.sh

This path used in this command should be absolute otherwise it won't work. Now you can call sudo -u user2 /home/user2/bin/test.sh from user1 shell.

answered Jul 3, 2019 by DareDev
• 6,890 points

Related Questions In Linux Administration

0 votes
1 answer

Downloading file using SSH from a server without web access

Run this command in  your terminal: scp your_username@remotehost.edu:foobar.txt ...READ MORE

answered Mar 5, 2019 in Linux Administration by ajs3033
• 7,300 points
1,087 views
0 votes
1 answer

Running a cron job at fixed intervals of time

Just use this instead: 0,30 * * * ...READ MORE

answered Jun 21, 2019 in Linux Administration by ajs3033
• 7,300 points
942 views
0 votes
1 answer

How to add user to a group in Linux system?

Hi@akhtar, In Linux, different users have different roles ...READ MORE

answered Aug 14, 2020 in Linux Administration by MD
• 95,460 points
793 views
0 votes
0 answers

unzip .gz file as a directory

I am new to Linux and had ...READ MORE

Apr 14, 2022 in Linux Administration by Soham
• 9,710 points
525 views
0 votes
1 answer
+1 vote
2 answers

Execute Pig Script from Grunt Shell

From your current directory run  pig -x local Then ...READ MORE

answered Oct 25, 2018 in Big Data Hadoop by Kunal
6,260 views
0 votes
1 answer

How to stop messages from being displayed on spark console?

In your log4j.properties file you need to ...READ MORE

answered Apr 24, 2018 in Apache Spark by kurt_cobain
• 9,350 points
5,580 views
0 votes
1 answer

How to get Spark dataset metadata?

There are a bunch of functions that ...READ MORE

answered Apr 26, 2018 in Apache Spark by kurt_cobain
• 9,350 points
4,921 views
0 votes
1 answer

How to find the group associated with a user in linux?

To list all the groups groups or to list ...READ MORE

answered Jun 21, 2019 in Linux Administration by DareDev
• 6,890 points
959 views
0 votes
1 answer

setting a variable output from a bash command

You can use $(command), which in my ...READ MORE

answered Feb 15, 2019 in Linux Administration by DareDev
• 6,890 points
2,548 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP