0

When trying to login with plink to a server I don't know how to pass the sudo password in the command correctly.

I use something like this:

plink -ssh -t <user>@<server> -pw <password> "echo -e <password>\n | sudo -S docker ... | cd <some path>"

The password contains 2 special chars - a ";" and a "*" char. In the first place the ";" char needs to be escaped with a "^" and a connection can be established. Then in the command I need to switch to sudo to use a docker command. Usually it should take the pass from the console. But somehow it seems that there a different escaping is needed. I tried some things and added single quotes around the password in the second place, tried it with and with the linebreak behind the pass but none of the things I tried worked. Anyone knows how to make it work?

Let's say an example password is: abc123;*

When I use this text in the bat-file:

SET password=abc123;*
plink -ssh -t <username>@<server> -pw abc123^;* "echo -e %password%\n | sudo -S docker exec -i <docker_container> <docker_container_path> |pwd"

What I would expect is that after this code the user would be in the docker container and a tomcat path would be displayed. But instead the current directory after the connect is displayed and below there are those lines:

[sudo] password for <user>: Sorry, try again
[sudo] password for <user>:
sudo: 1 incorrect password attempt

I tried diffent approaches to escape the password for the plink command like: SET password=abc123\;\* or SET password=abc123%%3B%%2A or SET password=abc123^;*

but none of them worked.

Note: Unfortunately changing the user password or setting the linux server to "no password" is not an option.

user2718671
  • 126
  • 1
  • 3
  • @MartinPrikryl: Well yes, it works. Without the echo there wouldn't be the incorrect password attempt message. – user2718671 Jan 03 '18 at 10:26
  • That's pretty ambiguous answer. **Did you test it successfully** in SSH terminal? – Martin Prikryl Jan 03 '18 at 10:35
  • @MartinPrikryl: Uhm, I think it works. I logged in with putty and tried that echo command. But all I get as feedback is incorrect password attempt. I also tried: echo ^| ... If I use just the echo I see the correct password when I escape the semicolon with \;. – user2718671 Jan 03 '18 at 11:53
  • So it does not work. – Martin Prikryl Jan 03 '18 at 12:59
  • @MartinPrikryl: Ah ok, thx. Sorry, I didn't know. My Sysadmin skills are very limited. ;) Since there was a callback that the password is incorrect I expected something was passed and it was just about another syntax error or something. – user2718671 Jan 03 '18 at 13:43
  • 3
    Possible duplicate of [sudo with password in one command line?](https://superuser.com/questions/67765/sudo-with-password-in-one-command-line) – Martin Prikryl Jan 03 '18 at 13:45

0 Answers0