LinuxQuestions.org
Help answer threads with 0 replies.
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 02-03-2004, 04:00 PM   #1
darthczyz
Member
 
Registered: May 2003
Distribution: Redhat 9
Posts: 49

Rep: Reputation: 15
su question


Hey folks,
Have a question about temporary root privileges. is there a way to set up 'su' so that you can send it the root password and get your root privileges all in one line? i'm trying to run 'su' from a java program to allow a user to edit network settings, and i'd much rather ask the user first for the password, and then send all of the information to the command line. are there any flags in su that would allow that?

thanks,
skiz
 
Old 02-03-2004, 04:07 PM   #2
Poprocks
Member
 
Registered: Sep 2003
Location: Toronto, Canada
Distribution: Slackware
Posts: 244

Rep: Reputation: 56
I don't quite understand your question... do you mean you want to become root just for one command or program? If so, try
Code:
su -c "command"
.

Hope that helps.
 
Old 02-03-2004, 04:19 PM   #3
darthczyz
Member
 
Registered: May 2003
Distribution: Redhat 9
Posts: 49

Original Poster
Rep: Reputation: 15
sorry, guess i phrased the question poorly. i only want to be root for one command, but i want to be able to execute the command and escalate the privilege all in one line. to clear up my mumbo jumbo ...

su -c /sbin/ifconfig will come back with another line asking me for the root password. it would be much easier in my program if somehow i could do it all on one line

su -c /sbin/ifconfig -p password

is this a possibility?

thanks for your help
 
Old 02-04-2004, 03:55 AM   #4
enigmasoldier
Member
 
Registered: Jul 2003
Location: Florence, Ky
Distribution: CentOS 3.3-4, OpenBSD 3.3, Fedora Core 4, Ubuntu, Novell Open Enterprise Server
Posts: 213

Rep: Reputation: 30
You would NEVER want to allow someone to type the root password on the command line. Why? Typing 'history | grep su' or 'history | less' would show it. This is a major security issue if you were to do it.

Use sudo. You can set up sudo so that anyone else can run certain commands without even entering a password.
Type 'visudo' to create an '/etc/sudoers' file. Make it contain something along the lines of:

ALL = ALL NOPASSWD: /sbin/ifconfig

Let me explain this a little. The format for the /etc/sudoers file is very simple
username host = command with the NOPASSWD statement optional. So all users from all hosts can run the ifconfig command without entering a password. If you wanted them to enter a password, they would just have to enter their own password.

You can also restrict it to a certain user or a certain host (computer) very easily. Make sure to create the '/etc/sudoers' file using the 'visudo' command, sudo gets really pissed off when there are errors in this file. I love using sudo.

Now, code your java program to create a system call to 'sudo ifconfig' and it will work. Beautiful, huh?

Link:
http://www.courtesan.com/sudo/man/sudoers.html
http://www.onlamp.com/pub/a/bsd/2002...y_Daemons.html
http://lists.freebsd.org/pipermail/f...il/001978.html
 
Old 02-04-2004, 08:56 AM   #5
darthczyz
Member
 
Registered: May 2003
Distribution: Redhat 9
Posts: 49

Original Poster
Rep: Reputation: 15
thanks enigma, unfortunately though, i'll be distributing this program to other computers that might not have sudo set up, so i don't really think that's an option. i guess i could make that known to users installing it.

i understand the thing about the root password being in the history, but the program would be using java to execute the commands, and i think java opens its own shell to execute commands. i wouldn't be sure that you still couldn't find the root password somehow, but it wouldn't be as blatant as putting it right in the command line.
thanks for your help though, looks like this just might not work.
 
Old 02-05-2004, 10:25 AM   #6
enigmasoldier
Member
 
Registered: Jul 2003
Location: Florence, Ky
Distribution: CentOS 3.3-4, OpenBSD 3.3, Fedora Core 4, Ubuntu, Novell Open Enterprise Server
Posts: 213

Rep: Reputation: 30
Why don't you bundle sudo with your software and have it install and confgure it for you. (With their permission of course) It sounds pretty trivial to me.
 
  


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
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 05:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 02:51 PM
2 part question: Speeding up MDK9.1/GNOME question wardialer Linux - Newbie 6 10-14-2004 04:16 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 03:02 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 01:53 PM

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

All times are GMT -5. The time now is 02:29 AM.

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