0

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 1

0

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

  1. Configure SSH to allow root login from localhost
  2. if not already done, run ssh-keygen
  3. run ssh-copy-id root@localhost, you can now ssh to root without a pw
  4. 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

3
  • 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 -sand configure the sudoers file to NOT ask for a PW for su. From then on you can just ssh someuser@somehost sudo su without a PW Jun 11, 2017 at 1:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .