LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-06-2014, 10:41 PM   #1
kcynice
Member
 
Registered: Sep 2008
Distribution: Slackware
Posts: 154

Rep: Reputation: 25
How to run a programm with anothter user?


The system has two normal user a and b. And, a was logined into the system. But there was a executable program owned by b, of course a had no permission to run it directly.
I want to know, if there was a way to run a program with the right user?
I do not want to change the current logined user, in another words, no logout.

Thanks.
 
Old 03-06-2014, 11:04 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

that is what su is for. Eg for use a to become user b..
Code:
su -l b
then execute the program.
Or do in one command:
Code:
su -c /path/to/executable a
Evo2.
 
Old 03-06-2014, 11:47 PM   #3
kcynice
Member
 
Registered: Sep 2008
Distribution: Slackware
Posts: 154

Original Poster
Rep: Reputation: 25
Thumbs up

Quote:
Originally Posted by evo2 View Post
Hi,

that is what su is for. Eg for use a to become user b..
Code:
su -l b
then execute the program.
Or do in one command:
Code:
su -c /path/to/executable a
Evo2.
OK. thanks. that might be the only way. it seems I have to obtain the password of user b.
 
Old 03-06-2014, 11:55 PM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,
Quote:
Originally Posted by kcynice View Post
OK. thanks. that might be the only way. it seems I have to obtain the password of user b.
Why not ask that user to make that program executable by all? Or, if you have read permission you can copy it and run the copy.

Evo2.
 
Old 03-07-2014, 04:22 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Alternatives:

1. put both users in the same group and use group perms
2. sudo (nb sudo to other user 'B', not as root)
 
Old 03-07-2014, 05:01 AM   #6
Smokey_justme
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 534

Rep: Reputation: 203Reputation: 203Reputation: 203
Wouldn't setuid resolve this? Or am I misunderstanding something?

P.S. To put both users in the same group and use group permissions is, in my personal opinion, the best way to do it..

Last edited by Smokey_justme; 03-07-2014 at 05:03 AM.
 
Old 03-07-2014, 11:29 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by Smokey_justme View Post
Wouldn't setuid resolve this? Or am I misunderstanding something?
You loose security control over the second user. Anyone that runs the program would become that user - and unless the program is CAREFULLY written, the user account could be completely taken over.
Quote:

P.S. To put both users in the same group and use group permissions is, in my personal opinion, the best way to do it..
That is the best way.
 
Old 03-08-2014, 08:14 AM   #8
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Quote:
Originally Posted by kcynice View Post
The system has two normal user a and b. And, a was logined into the system. But there was a executable program owned by b, of course a had no permission to run it directly.
I want to know, if there was a way to run a program with the right user?
I do not want to change the current logined user, in another words, no logout.
You (user b) can use ACL for this. ACL is specifically designed for this.
  1. Give execute permission for directory where the program is.
  2. Then, give read and execute permission for program/script file

Ex:
Code:
[b@gamma ~]$ ls -l /home/b/sayhello 
-rwx------. 1 b b 28 Mar  7 15:34 /home/b/sayhello

[b@gamma ~]$ setfacl -m u:a:x /home/b
[b@gamma ~]$ setfacl -m u:a:rx /home/b/sayhello

[a@gamma ~]$ /home/b/sayhello
Hello Ji
Here a and b are users
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run linux command from a different user from a jsp page which is run by tomcat etika Linux - Newbie 2 04-27-2011 11:53 AM
can not run c programm in COde blocks Ibrahim210 Linux - Newbie 1 07-13-2009 12:21 PM
How window in programm can be resized by another programm. rexStart Programming 1 09-23-2008 02:47 AM
Gconf-editor settings not sticking for root, sudo user, or user when run sandaili Fedora 1 07-19-2008 08:31 AM
run programm on startup ichbinesderelch Linux - General 6 08-18-2003 12:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration