-2

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 ...

[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.

harryz
  • 289
  • 2
  • 3
  • 10
  • 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

1 Answers1

0

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.

guntbert
  • 631
  • 9
  • 21
Corvar
  • 91
  • 9