How to perform "sudo" commands between servers?

Asked

Viewed 63 times

4

Before running a R script on server 'A' I have to restart Shiny-server on server 'B'.

/bin/ssh cabala@***.***.***.*** 'sudo service shiny-server restart'

I would like to enter a command into the R script on the 'A' server system() that left Shiny-server on the 'B' server. You would still have the problem of sending sudo password in this command.

  • 1

    Need to be automatic password entry? If yes, you can look at the argument -a of sudo (man sudo). If you want to enter the password when running the script this can help : system('sudo -kS service shiny-server restart', input = readline("Enter your password: "))

  • Yes, it is an internal routine and would have no problem automating the password entry.

1 answer

2


Go to server A and copy the key to server B. If you have not yet generated SSH Key, you do following the steps of this link

1) Copying the ssh key from Server A to Server B:

ssh-copy-id cabala@***.***.***.*** # IP ou DNS do Servidor B

2) Test ssh to see if you are logging in without password:

ssh cabala@***.***.***.*** # IP ou DNS do Servidor B

3) Make sure the user is allowed to use sudo by running the command you want:

sudo service shiny-server restart

After these steps you will be able to run the command remotely with no password required and you will be able to run the cron the way you mentioned.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.