Operating System - HP-UX
1822895 Members
3487 Online
109645 Solutions
New Discussion юеВ

sudo - no password prompt

 
Rahul_13
Advisor

sudo - no password prompt

I am writing a Shell script in which I first ssh to some servers then 'sudo su - user' and and execute some commands.

But when I use 'sudo su - user', it prompts for password.

Is there any way in which I can escape this password or provide the password in the sudo command line.

Please help.

Thanks,
Rahul
8 REPLIES 8
Rick Garland
Honored Contributor

Re: sudo - no password prompt

It is the NOPASSWD you are looking for

acct_name ALL=(ALL) NOPASSWD: ALL
Rahul_13
Advisor

Re: sudo - no password prompt

Hi Rick,

I did not get what you are saying. Can you please tell me where do I need to add the NOPASSWD entry.

Thanks,
Rahul

Rick Garland
Honored Contributor

Re: sudo - no password prompt

In the sudoers file, you can have a configuration similar to the following

ALL=(ALL) NOPASSWD: ALL

The NOPASSWD key word is included in the syntax as you create a rule in the sudoers file. In this example, this is pretty wide open in an environment. Says ALL systems have NOPASSWD and can run ALL commands.

Rahul_13
Advisor

Re: sudo - no password prompt

I don't have permissions to modify the sudoers file. Is there any other way in which I could escape the password.

I tried echo "$pass"|sudo su - user

But it does not seem to work.

-Rahul
Rick Garland
Honored Contributor

Re: sudo - no password prompt

Need that access to the sudoers file to add the NOPASSWD.



A. Clay Stephenson
Acclaimed Contributor

Re: sudo - no password prompt

Ask yourself. If a non super-user has the ability to modify the sudoers file, just how secure do you think sudo would be?
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor

Re: sudo - no password prompt

sudo is a method to give root access to selected users and selected commands. The system administrator must setup the sudoers file using visudo (do NOT edit the sudoers file with vi). If you do not have access to edit this file, you'll have to contact the system administrator.


Bill Hassell, sysadmin
A. Clay Stephenson
Acclaimed Contributor

Re: sudo - no password prompt

Sudo also has the ability to allow a command to executed as a particular user so that your su command should not be needed and careful configuration would be required so that this would not be exploited. You should really discuss with your sysadmin exactly what you are trying to accomplish and perhaps a better way will be found.
If it ain't broke, I can fix that.