How to remote execute ssh command a sudo command without password
you can tell sudo to skip password for some command.
e.g. in /etc/sudoers
archemar ALL = (www-data) NOPASSWD: /bin/rm -rf /var/www/log/upload.*
this allow me to use
sudo -u www-data /bin/rm -rf /var/www/log/upload.*
as archemar without password.
Note that
sudo -u www-data rm -rf /var/www/log/upload.*
won't work (will ask a password) as rm
differ from /bin/rm
.
Be sure to edit /etc/sudoers
using visudo
command.
Once you've reach advanced level, you might whish to have your own sudo files in /etc/sudoers.d
.
The most simple way is to provide password from stdin
if your sudo
supports that (-S key)
ssh -t admin@remotehost "echo <yourpassword> |sudo -S <yourcommand>"