LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 11:41 PM   #1
kcynice
Member
 
Registered: Sep 2008
Posts: 111

Rep: Reputation: 18
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-07-2014, 12:04 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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-07-2014, 12:47 AM   #3
kcynice
Member
 
Registered: Sep 2008
Posts: 111

Original Poster
Rep: Reputation: 18
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-07-2014, 12:55 AM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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, 05:22 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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, 06: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 06:03 AM.
 
Old 03-08-2014, 12:29 AM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,711

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
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, 09:14 AM   #8
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 525

Rep: Reputation: 141Reputation: 141
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:53 PM
can not run c programm in COde blocks Ibrahim210 Linux - Newbie 1 07-13-2009 01:21 PM
How window in programm can be resized by another programm. rexStart Programming 1 09-23-2008 03:47 AM
Gconf-editor settings not sticking for root, sudo user, or user when run sandaili Fedora 1 07-19-2008 09:31 AM
run programm on startup ichbinesderelch Linux - General 6 08-18-2003 01:26 PM

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

All times are GMT -5. The time now is 05:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration