Kumakaja
Kumakaja

Reputation: 89

How can I execute a command with "sudo" in a python/bash/ruby script via SSH?

On a remote server I can execute a certain command only via "sudo". The authentication is done via a certificate. So when I login via SSH by a bash script, python, ruby or something else, how can I execute a certain command with sudo?

Upvotes: 1

Views: 273

Answers (1)

Farhad Farahi
Farhad Farahi

Reputation: 39437

The proper way of doing this is using a configuration management solution, like ansible, You can use become directive to run script/command with sudo privileges from a remote client.

If there is only one box or you need to schedule, you can use /etc/crontab and run it with root user at desired interval.

Upvotes: 1

Related Questions