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 in Linux Administration by Atul
• 5,530 points
35 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 by DareDev
• 6,810 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 in Linux Administration by ajs3033
• 7,280 points
50 views
0 votes
1 answer

Running a cron job at fixed intervals of time

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

answered Jun 20 in Linux Administration by ajs3033
• 7,280 points
34 views
0 votes
1 answer

How to display a simple list of all disks, like this /dev/sda /dev/sdb ?

You can list all the disk in ...READ MORE

answered Jul 12, 2018 in Linux Administration by DearestOne
• 200 points
105 views
0 votes
1 answer
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
855 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,260 points
1,210 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,260 points
415 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 20 in Linux Administration by DareDev
• 6,810 points
40 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 in Linux Administration by DareDev
• 6,810 points
83 views