NOTE: The servers does not share the same password but I will setup no-password login at first.
Here's the use case, I need to do these below step by step in my deploy.sh
:
- scp files to remote servers'
/opt/bin
directory, which requires root permission - After that, ssh into remote servers and run
sudo install.sh
, which also requires root permission - Login as root is not allowed by servers
I noticed there's way[1] to ssh
and run sudo command but it seems not work for scp
.
It really bothered me a lot ...
[1]https://stackoverflow.com/questions/10310299/proper-way-to-sudo-over-ssh
BTW: I think one of the possible way is that scp files to a normal directory and then ssh and run sudo mv * /opt/bin; sudo install.sh
.