Sudo password in shell file


Login or Register to Reply

 
Thread Tools Search this Thread
# 8  
Old 09-05-2018
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; 09-19-2018 at 05:47 AM..
This User Gave Thanks to rbatte1 For This Post:
Neo (09-17-2018)
# 9  
Old 09-14-2018
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; 09-19-2018 at 05:47 AM.. Reason: Removed invalid colon in suggestion
# 10  
Old 09-14-2018
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 09-14-2018
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 09-14-2018
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; 09-14-2018 at 02:30 PM..
# 13  
Old 09-17-2018
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 09-18-2018
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 or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Sudo command prompt for a password wtolentino AIX 2 03-15-2018 11:27 AM
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 -s without password prompt krk UNIX for Dummies Questions & Answers 3 01-04-2013 08:57 PM
Sudo + Nohup = no password? nitrobass24 Red Hat 4 07-30-2012 10:33 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
Problem with password expire and sudo. sparcman Solaris 2 04-14-2010 01:18 PM
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, use in script without prompt for password gauravgrover50 Shell Programming and Scripting 4 04-25-2009 08:26 AM
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, root password penguin-friend Linux 5 11-02-2005 02:27 AM
sudo in OS X shell script without password prompt?? Brad_GNET UNIX for Dummies Questions & Answers 1 07-29-2005 06:36 PM