Results 1 to 6 of 6
So I just got into Bash and I'm having some fun with it. So I'm making a script that just simply shutsdown the computer. The problem I'm having, with the ...
- 01-07-2010 #1Just Joined!
- Join Date
- Aug 2009
- Posts
- 4
Bash: how to enter password for sudo
So I just got into Bash and I'm having some fun with it. So I'm making a script that just simply shutsdown the computer. The problem I'm having, with the code presented below, is when the script is ran it ask for a password. So what am I doing wrong here?
Code:#!/bin/sh echo "shutting down now!" sudo PASSWORD shutdown -h now
- 01-07-2010 #2
I know almost nothing about bash scripts, but I can say with fair confidence that sudo PASSWORD isn't going to work. Just like if you typed that into a terminal, the next command wouldn't run with elevated privileges.
It should beor justCode:sudo shutdown -h now
If you want a user to be able to run a command with elevated privileges and without being asked for a password, you need to edit the /etc/sudoers file and specify it there.Code:sudo halt
Sudoers Manual
- 01-11-2010 #3Just Joined!
- Join Date
- Aug 2009
- Posts
- 4
how would I go about editing the /etc/sudoers file?
- 01-11-2010 #4Usually this defaults to using vi as the editor. Some distros have changed this default behavior to an easier editor like nano.Code:
su visudo
If it uses vi, and you prefer nano, do
Code:su EDITOR=nano visudo
- 01-12-2010 #5Just Joined!
- Join Date
- Aug 2009
- Posts
- 4
I'm sorry I didn't ask that right. I know how to edit the file I'm just not quite sure what code to use to get this going.
- 01-12-2010 #6
Here is a pretty detailed example sudoers file to give you an idea of how to do things.
http://www.gratisoft.us/sudo/sample.sudoers
Basically, you'll need something like
username could also be a group the user belongs to.Code:username ALL = NOPASSWD: /sbin/halt


Reply With Quote