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:

  1. scp files to remote servers' /opt/bin directory, which requires root permission
  2. After that, ssh into remote servers and run sudo install.sh, which also requires root permission
  3. 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 ...


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.

  • 1
    you can provide commands in /etc/sudoers with NOPASSWD. Then you can run sudo without prompting for password. – Navern Mar 31 '15 at 23:00

Bring the mountain to the prophet?

ssh user@remote "sudo scp -r user@local:/path/to/files /opt/bin"

It seems like that is a whole lot of privilege with nary a password to be seen, which would make me nervous.

  • How the remote scp local without input local's password? – harryz Mar 28 '15 at 2:58
  • By generating a key on the remote system as root, and putting it in the local user/machines .ssh/authorized_keys – Corvar Mar 28 '15 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.