I’m trying to run a script on a remote server with either password credentials or .pem key access and I’m getting errors no matter which solution I’ve found etc.
bash script content:
#!/bin/bash
sudo fdisk -l
ssh -T -i "~/.ssh/keys/key.pem" ubuntu@host "sudo bash <(wget -qO- http://host.com/do.sh)"
Error: bash: /dev/fd/63: No such file or director
ssh [email protected] 'echo "password" | sudo bash <(wget -qO- http://www.host.io/do.sh)'
Error: sudo: a password is required
ssh -t [email protected] "echo password | sudo fdisk -l"
Works but still gives me the password propmt
echo -t pass | ssh user@host "sudo bash <(wget -qO- http://host.com/do.sh)"
echo -tt pass | ssh user@host "sudo bash <(wget -qO- http://host.com/do.sh)"
Error: bash: /dev/fd/63: No such file or directory
// And I also get the password prompt
echo -tT pass | ssh user@host "sudo bash <(wget -qO- http://host.com/do.sh)"
Error: sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
// And I also get the password prompt
// This works but I still get the password propmt
ssh user@host 'echo "password" | sudo -S sudo fdisk -l'
These are different variations of the supposed solutions from other places.
What I’m trying to do:
- Is to run a script from a URL on the remote server while echoing the password to the cmd so I don’t get propmt to input the password manually.
- To be able to do the same thing above with using the .pem key variant also
2
Answers
For an explanation for commands except the first one, You can’t do stdin-redirect a password to ssh if
ssh
requires interactively.ssh
only allows manual typing if you use a password.Your first error said that bash can’t read a file descriptor. So ssh via
~/.ssh/keys/key.pem
works. To run the shell command on the fly,Does your script really need to run with sudo??
If not, then try this: