Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Sudo password in shell file

Tags
file, password, shell, shell scripts, sudo

👤 Login to reply

 
Thread Tools Search this Thread
# 8  
Old 2 Weeks Ago
I'm sorry, I read the first post and assumed.

I'm a little confused about the -p flag for su though. From my manual page, I see this:
Quote:
-m, --preserve-environment
do not reset HOME, SHELL, USER, LOGNAME environment variables

-p same as -m
I think you are wanting to code in the password so you don't have to key it in. If that is the case, use a sudo rule to perform the operation you want to do and write it to not require a password.

Tools such as su, ssh etc. are written to prevent command line or scripted use (although you can su if you are already root)

A rule such as:-
Code:
%your-group    ALL = (oracle) NOPASSWD:  ALL

.... should let people in the specified group do anything as the oracle account without a password check. You would use it thus:-
Code:
sudo -u $ou_user some_command_here

BEWARE!
This may expose you to risk! Do you really want to grant so much? Maybe you you allow less than everything when running as oracle




I hope that this helps,
Robin

Last edited by rbatte1; 2 Days Ago at 05:47 AM..
The Following User Says Thank You to rbatte1 For This Useful Post:
Neo (4 Days Ago)
# 9  
Old 6 Days Ago
Quote:
Originally Posted by rbatte1
I'm sorry, I read the first post and assumed.

I'm a little confused about the -p flag for su though. From my manual page, I see this:I think you are wanting to code in the password so you don't have to key it in. If that is the case, use a sudo rule to perform the operation you want to do and write it to not require a password.

Tools such as su, ssh etc. are written to prevent command line or scripted use (although you can su if you are already root)

A rule such as:-
Code:
%your-group    ALL = (oracle) NOPASSWD:  ALL

.... should let people in the specified group do anything as the oracle account without a password check. You would use it thus:-
Code:
sudo -u $ou_user some_command_here

BEWARE!
This may expose you to risk! Do you really want to grant so much? Maybe you you allow less than everything when running as oracle




I hope that this helps,
Robin
hi robin,

sorry for delayed reply... specifying oracle username is mandatory, as i cant login to that remote box directly with oracle user(some network restrictions prevent that). Only i can login into initial user and then I need to switch the user..However did not get breakthrough as password is not allowed to be specified for su command..

Last edited by rbatte1; 2 Days Ago at 05:47 AM.. Reason: Removed invalid colon in suggestion
# 10  
Old 6 Days Ago
Please forgive if Im totally wrong, a bit shaken after having an accident with my motorbike... but we were many bikes to fall as a lorry spilled fuel and the road...
Code:
ssh -i $key $os_user@$ip
sudo -u $ou_user -p $ou_pass   -- i am getting error here...its not taking sudo password
. PRD 
"sqlplus / as sysdba<<EOF
ALTER USER $unlock_user ACCOUNT UNLOCK;   
EOF  
"

I am not sure what is going on here, it seemed to me that after ssh, you are on a another connection with a new shell, no?
So su or sudo wont work as such IMHO

Sorry bad headhache, leaving...
# 11  
Old 6 Days Ago
Quote:
Originally Posted by vbe
Please forgive if Im totally wrong, a bit shaken after having an accident with my motorbike... but we were many bikes to fall as a lorry spilled fuel and the road...
Code:
ssh -i $key $os_user@$ip
sudo -u $ou_user -p $ou_pass   -- i am getting error here...its not taking sudo password
. PRD 
"sqlplus / as sysdba<<EOF
ALTER USER $unlock_user ACCOUNT UNLOCK;   
EOF  
"

I am not sure what is going on here, it seemed to me that after ssh, you are on a another connection with a new shell, no?
So su or sudo wont work as such IMHO

Sorry bad headhache, leaving...
Hi,

Hope you are ok ?

Yes , after ssh i will be on another remote box, where i need to switch to oracle user by using su ...

How ever i got some google information and previous reply from robin sudo su wont ask for password where just su shall ask ( I need to to give a try this a work around)
# 12  
Old 6 Days Ago
Just took some pain killers, apart scratches and bruises headache and bad back all is OK...
What I ment was the line after ssh ( su etc... ) would be executed once you left that new shell... So you would have to use a heredoc here too...

But again, since I have not all my head I was hoping someone would pick up from here and confirm and if so help you through

Last edited by vbe; 6 Days Ago at 02:30 PM..
# 13  
Old 4 Days Ago
Sory for being confused, but in what way does my suggestion not meet your need. If I can understand it, then I may be able to help.

I think that:-
  • You are using ssh to connect to the server as yourself
  • You want to then use sudo to run a command as the user oracle
  • is that correct? If so, does having the suggested sudo rule (adjusted to consider my warning) help at all? One of us is missing something - and I'm happy to accept it is me, but I don't understand what it is yet. Can you explain a little more?

    Perhaps a scraping of your screen as you run through would help me see it.



    Thanks, in advance,
    Robin
    # 14  
    Old 3 Days Ago
    Quote:
    Originally Posted by rbatte1
    Sory for being confused, but in what way does my suggestion not meet your need. If I can understand it, then I may be able to help.

    I think that:-
  • You are using ssh to connect to the server as yourself
  • You want to then use sudo to run a command as the user oracle
  • is that correct? If so, does having the suggested sudo rule (adjusted to consider my warning) help at all? One of us is missing something - and I'm happy to accept it is me, but I don't understand what it is yet. Can you explain a little more?

    Perhaps a scraping of your screen as you run through would help me see it.



    Thanks, in advance,
    Robin
    Hi Robin,

    Thanks for your kind reply.. apologies for delay.
    Yes, below understanding is correct
    [*]You are using ssh to connect to the server as yourself[*]You want to then use sudo to run a command as the user oracle

    However mentioning just sudo oracle is not working..I think i am missing some settings in sudo file, I am not sure which i am missing.. Like you suggested I have added oracle to wheel group visudo file..but not working

    OR
    it should allow me to just su oracle and accept password ( i think this not viable option as per lot of google information)
    suggest me
    👤 Login to reply

    « Previous Thread | Next Thread »
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes

    More UNIX and Linux Forum Topics You Might Find Helpful
    Thread Thread Starter Forum Replies Last Post
    Sudo reads password from a .cfg file dellanicholson UNIX for Dummies Questions & Answers 4 10-01-2015 11:23 AM
    Sudo without password Solaris 11.2 akame Solaris 5 10-29-2014 06:57 AM
    Sudo Password Prompt over SSH scotbuff Red Hat 1 09-18-2013 11:49 AM
    ssh foo.com sudo command - Prompts for sudo password as visible text. Help? fluoborate Shell Programming and Scripting 9 11-02-2011 02:18 PM
    password in sudo script pua06 Shell Programming and Scripting 5 07-18-2011 12:30 AM
    password getting displayed using sudo ningy Shell Programming and Scripting 1 04-08-2010 05:46 PM
    Sudo ask for password lo-lp-kl AIX 2 06-03-2009 06:16 PM
    sudo command with password chebarbudo Shell Programming and Scripting 1 12-29-2008 07:13 AM
    verify sudo password mdpalow Shell Programming and Scripting 0 12-20-2007 09:53 PM
    sudo in OS X shell script without password prompt?? Brad_GNET UNIX for Dummies Questions & Answers 1 07-29-2005 06:36 PM


    All times are GMT -4. The time now is 11:53 AM.

    Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
    UNIX.COM Login
    Username:
    Password:  
    Show Password