LinuxQuestions.org
Register a domain and help support LQ
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 09-09-2010, 03:13 AM   #1
ubuntuv
Member
 
Registered: Jan 2010
Posts: 64

Rep: Reputation: 0
Sudo command occasionally asks for root password


Hi,

In Ubuntu 10.04, I logged in as user1 and when I open a new terminal and issue any command it is asking password.

user@ubun-laptop:~$ sudo ifconfig
[sudo] password for user:

It is asking for password only for first time. From the next command onwards it is not asking.

Can some one please tell me if it is possible to issue ONLY ONE COMMAND, in which even if the password request comes, it will automatically fill the password.

Just like "ps -elf | grep NetworkManager". I am expecting any combination of commands in a single line, so that password is filled automatically IF PASSWORD IS ASKED. If password is not asked, the command must be executed.

Thanks
uv.
 
Old 09-09-2010, 03:23 AM   #2
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
Read the document about visudo.
 
Old 09-09-2010, 03:31 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,253

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
You have lost me a little bit uv
Quote:
when I open a new terminal and issue any command it is asking password
Does this mean if you enter:
Code:
user@ubun-laptop:~$ ls
This will ask for a password?? If so then you have a bigger issue
Quote:
It is asking for password only for first time. From the next command onwards it is not asking.
This is not exactly correct either (or at least it shouldn't be). The use of the sudo command is also timed (can't remember off the top of my head how long).
So yes if your commands are consecutive you will only get asked once, but if you have a lengthy break in between it will ask again. This is a security option in case
you leave your machine unlocked and another user then uses your elevated privileges to be nasty.

The rest of your query would appear to come from a Windows based query, ie once in Windows as an admin you can break your system any way you like.
The idea behind being asked to provide a password is to let you know that what you are about to do has consequences for all users on the system (even though it might only be you).

Finally, if you really want to be god (ie root in linux) so that you are not bothered with pesky requests for passwords that might help you think about what you are about to do
could be a bad thing, the following should suffice:
Code:
sudo su - root
Once you enter your password here you will be root and can now run any command you like and will not be asked to check.
 
Old 09-09-2010, 03:42 AM   #4
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
Quote:
Originally Posted by grail View Post
The use of the sudo command is also timed (can't remember off the top of my head how long).
15 minutes, if I remember correctly.
Quote:
Originally Posted by grail View Post
Finally, if you really want to be god (ie root in linux) so that you are not bothered with pesky requests for passwords that might help you think about what you are about to do
could be a bad thing, the following should suffice:
Code:
sudo su - root
Once you enter your password here you will be root and can now run any command you like and will not be asked to check.
Just need 'sudo su -', 'root' is not necessary.
 
Old 09-09-2010, 06:31 AM   #5
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Rep: Reputation: 48
I do
$sudo -i
enter password:
~# Now do things as root .

Though usually i run
$sudo command

Ofcourse , you can see man page of sudo for more details

Last edited by sumeet inani; 09-09-2010 at 06:33 AM.
 
Old 09-09-2010, 06:45 AM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
read man sudoers; the option that you're looking for is timestamp_timeout

Use visudo to edit the sudoers file (no experience with it)
 
Old 09-09-2010, 07:23 AM   #7
ubuntuv
Member
 
Registered: Jan 2010
Posts: 64

Original Poster
Rep: Reputation: 0
Thanks a lot for the replies.

Actually, I am trying issuing the ssh command from the windows machine. I have to fetch the results using sudo command.

When it asks for password, my automation code fails. For that reason, i need to make any one line code, which solves this purpose.

Thanks in advance
uv
 
Old 09-09-2010, 07:37 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Also, in sudo, you enter your password, NOT the root password. In fact, in your original post, it said "[sudo] password for user:".
 
Old 09-10-2010, 05:13 AM   #9
ubuntuv
Member
 
Registered: Jan 2010
Posts: 64

Original Poster
Rep: Reputation: 0
Yes MTK. Sorry about typo error.

I am looking for a one line solution, which is capable to execute even if 'password' is being asked. This would help me a lot.

Thanks
uv.
 
Old 09-10-2010, 08:03 AM   #10
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
The way sudo works is that it remembers the password temporarily and then you have to enter it again after a certain time.

So is this for a shell script or something where you only want the user to enter the password once at the beginning?
 
Old 09-10-2010, 05:01 PM   #11
ubuntuv
Member
 
Registered: Jan 2010
Posts: 64

Original Poster
Rep: Reputation: 0
I have developed a script from windows machine which sends series of commands via ssh. If the password is being asked, my script doesnt work from remote machine. I am searching for a solution in this scenario. Only that initial 'password' request is blocking my way.

-uv
 
Old 09-10-2010, 05:29 PM   #12
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Rep: Reputation: 35
You can solve this using three methods:
  1. Edit the sudoers file (on the remote machine) with visudo so the password is no longer required.
  2. Force sudo to always ask for the password so your script knows it has to give it the password.
  3. Use tricky code (for a shell script) to parse sudo's output and determine if it's waiting for a password.

Method 1 is probably the easiest and cleanest method (in my opinion), but it is not portable (you would have to do this on every remote machine.)

Method 2 is the "portable" method. There are a couple ways to do this, but the easiest (and my personal preference) would be to use the "-k" switch to sudo. This will cause it to always ask for a password.

Method 3 is ugly and difficult. I do not recommend it.

I hope this helps.
 
Old 09-10-2010, 05:39 PM   #13
ubuntuv
Member
 
Registered: Jan 2010
Posts: 64

Original Poster
Rep: Reputation: 0
Hi,

I would prefer to go for option 1. Please help me in editing my Ubuntu10.04 machine.

Here is the snap of the code
Quote:
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults env_reset
Defaults visiblepw

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(ALL) ALL
user ALL=(ALL) ALL
Please tell me the changes that has to be made in this file.

-uv
 
Old 09-10-2010, 05:46 PM   #14
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Rep: Reputation: 35
Change:
Code:
user ALL=(ALL) ALL
to:
Code:
user ALL=(ALL) NOPASSWD: ALL
The default, if no behavior is specified, is to ask for a password the first time, then keep that authorization for five minutes (according to the man page for Gentoo's sudo). This sets it to never ask for a password, no matter which commands are run, for the user "user".

Beware that this is a security risk -- if you leave a shell open accidentally, anyone can walk up and run any command they want.

You can find more information on the sudoers file online.

I hope this helps.
 
Old 09-12-2010, 09:37 AM   #15
ubuntuv
Member
 
Registered: Jan 2010
Posts: 64

Original Poster
Rep: Reputation: 0
Thanks crosstalk,

But it didnot solve the purpose, even in the same machine i opened a new windows, i issue the command

>sudo ifconfig

it is asking for password. for the second command onwards it is not asking.

Is there any other solution
 
  


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
[SOLVED] Ubuntu recovery mode asks for root password Changes Linux - Newbie 15 10-12-2009 05:48 AM
Install skype on acer one. Asks for root password. don't know where to get this congercod Linux - Newbie 4 02-13-2009 09:08 AM
is possible that sudo always asks the password? Lantius Linux - Software 5 05-09-2007 05:31 PM
SUSE asks for root password at logoff (how do I shut this off?) monkeyboy73 Linux - Desktop 4 12-14-2006 10:28 PM
Redhat 8 asks for root password before dialling head8k Linux - Newbie 9 02-21-2003 05:52 PM


All times are GMT -5. The time now is 01:03 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