LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2008, 08:17 PM   #1
rabbit2345
Member
 
Registered: Apr 2007
Location: SC
Distribution: Kubuntu 20.04 LTS
Posts: 378

Rep: Reputation: 41
how to expect with sudo?


im trying to get my computer to refresh my sources on login, but i need root privedges so what i have in mind is something like this:

Code:
sudo zypper ref

expect "root's password:" {send "<password>\n"}
it doesnt work, did i do something wrong?
 
Old 04-26-2008, 10:08 PM   #2
chadl
Member
 
Registered: Sep 2005
Location: US
Distribution: Gentoo AMD64 Testing
Posts: 129

Rep: Reputation: 16
The best way to do that is to edit the sudoers file to allow that command to be run through sudo without a password (that way running "sudo command" will not prompt for a password, by-passing this issue). It is a large security hole to have your password anywhere in plain-text.

The sudoers file can be edited by running "sudo visudo", and it will check the file for errors when you try to save your changes.

Do read the man page though, as the sudoers file is not forgiving to syntax errors.
 
Old 04-28-2008, 04:23 PM   #3
rabbit2345
Member
 
Registered: Apr 2007
Location: SC
Distribution: Kubuntu 20.04 LTS
Posts: 378

Original Poster
Rep: Reputation: 41
is it possible that i can execute a certain command as sudo, like

sudo zypper ref

but that s the only command i can run without a password?


btw, i found this attached to a music file i (legally) downloaded, does it mean anything?

00002545 00000A54 0000EF32 00007DD5 0002A178 0002EC0F 00009734 000092F9 00034192 0003190F

just curious

Last edited by rabbit2345; 04-28-2008 at 04:25 PM.
 
Old 04-28-2008, 04:29 PM   #4
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by rabbit2345
is it possible that i can execute a certain command as sudo, like

sudo zypper ref

but that s the only command i can run without a password?
Sure. Here's just one example from the manpages for sudoers(5):
Code:
ray    rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
(As mentioned, read and understand the manpages to make sure you set things up correctly.)
 
Old 04-28-2008, 07:58 PM   #5
rabbit2345
Member
 
Registered: Apr 2007
Location: SC
Distribution: Kubuntu 20.04 LTS
Posts: 378

Original Poster
Rep: Reputation: 41
ok, I edited my /etc/sudoers file according to the man page, but it still asks me for a root password

here is my /etc/sudoers:

Code:
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

Cmnd_Alias SHUTDOWN = /sbin/shutdown

# Defaults specification

# Prevent environment variables from influencing programs in an
# unexpected or harmful way (CVE-2005-2959, CVE-2005-4158, CVE-2006-0151)
Defaults always_set_home
Defaults env_reset

Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE"
# Comment out the preceding line and uncomment the following one if you need
# to use special input methods. This may allow users to compromise  the root
# account if they are allowed to run commands without authentication.
#Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE XMODIFIERS GTK_IM_MODULE QT_IM_MODULE QT_IM_SWITCHER"

# In the default (unconfigured) configuration, sudo asks for the root password.
# This allows use of an ordinary user account for administration of a freshly
# installed system. When configuring sudo, delete the two
# following lines:
Defaults targetpw   # ask for the password of the target user i.e. root
ALL ALL=(ALL) ALL   # WARNING! Only use this together with 'Defaults targetpw'!

# Runas alias specification


# User privilege specification
root	ALL=(ALL) SETENV: ALL
brian	ALL = NOPASSWD:/usr/bin/zypper refresh

# Uncomment to allow people in group wheel to run all commands
# and set environment variables.
%wheel	ALL=(ALL) SETENV: ALL

# Same thing without a password
%wheel	ALL=(ALL) NOPASSWD: SETENV: ALL

# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now
brian is me

thanks,
rabbit2345
 
  


Reply

Tags
sudo



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
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
PHP-CLI, expect, dump and sudo problem gw1500se Programming 2 03-05-2008 07:43 PM
LXer: sudo, or not sudo: that is the question LXer Syndicated Linux News 0 02-07-2008 05:40 PM
Restricting Editing in Sudo (Advanced Sudo Question) LinuxGeek Linux - Software 4 11-04-2006 03:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:14 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
Open Source Consulting | Domain Registration