SSH to server with auth key then sudo su with some command

Hi All,

I want following:

SSH to a server with auth key. Then sudo su and give a password. Then a command.

ssh -i /config/ssh_keys/no_pass -o StrictHostKeyChecking=no [email protected] -p 1234

This part is working when I do this from command line of HAOS.

But the rest I don’t know. Can someone assist me?

Thanks

Try something like this format with the " and ’

 command_on: "ssh -i /config/ssh_keys/key1 -o 'StrictHostKeyChecking=no' [email protected] 'poweroff'"

Disabled root for ssh. use a different user. When I’m in the SSH session I do sudo su with a password.

"ssh -i /config/ssh_keys/no_pass -o StrictHostKeyChecking=no [email protected] -p 1234 sudo -S whatevercommand"

Just a suggestion to try this. Never tried other than using root.

this will ask for password for user root

What I did now is following:

command_line:
  - switch:
      name: "Backup Full manual"
      unique_id: "154c03eb-abb8-4b86-941f-d6d3f0495c76"
      command_on: 'ssh -i /config/ssh_keys/no_pass -o StrictHostKeyChecking=no [email protected] -p 1234 "sudo -S /usr/local/sbin/backup-full.sh"'

  - switch:
      name: "MVPS - Backup dB manual"
      unique_id: "154c03eb-abb8-4b86-941f-d6d3f0495c76"
      command_on: 'ssh -i /config/ssh_keys/no_pass -o StrictHostKeyChecking=no [email protected] -p 1234 "sudo -S /usr/local/sbin/backup-db.sh"'

On server to root user

visudo

add this line:

<user> ALL=(ALL) NOPASSWD: /usr/local/sbin/backup-full.sh,/usr/local/sbin/backup-db.sh

This gives the without root permissions the rights to execute only the lines behind the NOPASSWD.

This works.