SSH Command – Why Does This SSH Command Not Work?

piperootsshsudo

I'm trying to do the following but it's not quite right.

cat ~/Desktop/blah.png | ssh -t -t trusktr@50.116.4.56 "cat | sudo -i 'cat | /path/to/blah.png'"

I have my public ssh key in the trusktr@50.116.4.56 user's .ssh folder, so no initial password is needed. When the sudo -i command finally starts, it prompts me for the root password, but immediately fails as if I had pressed enter but I didn't even touch the keyboard. I have a feeling maybe the cat command is being catted into the password prompt. The output looks like this:

trusktr@LENOVO-PC ~
$ cat ~/Desktop/win-8.1-missing-lockscreen-setting.png | ssh -t -t trusktr@50.116.4.56 "cat | sudo -i 'cat > /srv/http/default/htdocs/~/img/win-8.1-missing-lockscreen-setting.png'"
tcgetattr: Not a character device
[sudo] password for root:
You type like i drive.
[sudo] password for root:
Your mind just hasn't been the same since the electro-shock, has it?
[sudo] password for root:
Maybe if you used more than just two fingers...
sudo: 3 incorrect password attempts
Connection to 50.116.4.56 closed.

I don't have direct ssh access through the root user, only through a normal user with access to sudo using the root password.

How might I cat the image through ssh, through the non-root user, into the root location all in a single command?

Best Answer

It does not work because you are cating blah.png into sudo, which is not a valid password.

This should combine the needed commands onto one line:

scp ~/Desktop/blah.png trusktr@50.116.4.56:~/ && ssh -t -t trusktr@50.116.4.56 "sudo cp ~/blah.png /path/to/blah.png && rm ~/blah.png"
Related Question