0

The problem is that I want to run certain ssh commands (Or scripts) from computerA to computerB without using a password.

Examples:

ssh apple@computerB 'poweroff'
ssh apple@computerB "killall firefox; systemctl enable apache; firefox"
ssh apple@computerB < superscript.txt

I also want to do this as secure as I can get it. I should not be able to ssh to computerB if I simply open up a terminal. And obviously not be able to edit the scripts/programs and run them afterwards.

I was thinking about using SUID and a different user with ssh keys to access the computer but there are security concerns regarding SUID and interpreted scripts.

Do anyone have any suggestions?

Saft
  • 36
  • 4

1 Answers1

0

Rather than having SUID programs on the SSH host, it's better to connect as a user with the required privileges, but to bind a specific command to that key.

We do that in the target user's .ssh/authorized_keys file. For example,

command="poweroff" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJQwKcn2AJxNpuzRM/SfJLn0UEXCMmAmI2Xdqeng4nB9 saft@home

If we want to use one of several commands, we can use a script that interprets $SSH_ORIGINAL_COMMAND appropriately:

#!/bin/sh

case "$SSH_ORIGINAL_COMMAND" in
  poweroff)
    exec poweroff
    ;;
  firefox)
    killall firefox; systemctl enable apache; exec firefox
    ;;
  *)
    printf '%s\n' >&2 \
        "Unrecognised command `$SSH_ORIGINAL_COMMAND'" \
        'Valid commands are:' \
        ' * poweroff' \
        ' * firefox'
    exit 1
    ;;
esac
Toby Speight
  • 8,460
  • 3
  • 26
  • 50