I need to log in to console as a super user through a shell script without typing password. Password should be hard coded to the script. ex- sudo su psadmin(psadmin is my username).
1 Answer
First of all: Review your control flow, what you want to do is not a good idea.
That said, there is an easy way to achieve what you want without hardcoding a PW: SSH to yourself
- Configure SSH to allow root login from localhost
- if not already done, run
ssh-keygen
- run
ssh-copy-id root@localhost
, you can now ssh to root without a pw - start your script via
sshroot@localhost /path/to/script
Again: I advise strongly not to do that, it might be much easier to adapt your sudoers
file to allow sudo /path/to/script
without a PW
-
As per the requirement i can't do it coz i don't have permission. I need to run this(shell script) on 12 servers. Jun 10, 2017 at 8:52
-
Actually i'm connecting to server using ssh.First i connects to a bridge and then connect to the server. After that i need to login there as a sudo su psadmin. That's the requirement i'm having current now. Jun 10, 2017 at 9:03
-
So once per server you login manually run
sudo -s
and configure the sudoers file to NOT ask for a PW forsu
. From then on you can justssh someuser@somehost sudo su
without a PW Jun 11, 2017 at 1:41