1

I would like to create a simple script to download and install a program over ssh.

#!/bin/bash
echo "Welcher Rechner?"
read nummer
echo "Verbinde zu APC "$nummer
apc=apc$nummer.local
sshpass -f .pass_file scp $HOME/autoconfig/.filius_update.sh dvadmin@$apc:$HOME/
sshpass -f .pass_file scp $HOME/autoconfig/filiusurl dvadmin@$apc:$HOME/
sshpass -f .pass_file scp $HOME/autoconfig/.pass_file.sh dvadmin@$apc:$HOME/.pass_file.sh
sshpass -f .pass_file ssh dvadmin@$apc 'export SUDO_ASKPASS=${HOME}/.pass_file.sh; sudo -A chmod +x ./.filius_update.sh && ./.filius_update.sh'
sshpass -f .pass_file ssh dvadmin@$apc 'export SUDO_ASKPASS=${HOME}/.pass_file.sh; sudo -A rm ./.pass_file.sh && rm filius.deb && rm filiusurl && rm .filius_update.sh'

But the terminal send me an error that I have to configure askpass:

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: A password is required
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: A password is required

I don't understand what did I wrong.

Thank you in advice.

Raffa
  • 32,237
DonPIZI
  • 11
  • You are running sudo in a remote shell without a terminal device ... As a security feature sudo requires the password to be intered/transmitted through a terminal/virtual terminal device ... See for example similar sudo: unable to allocate pty: No such device ... Also see the part about sudo -S here: https://askubuntu.com/a/1465841 – Raffa May 10 '23 at 14:41
  • On the other hand, I'm not sure even SUDO_ASKPASS can work in a remote shell like that ... I haven't tested it to confirm, but in theory it shouldn't work that way(at least not with available normal methods/mechanisms) ... You most likely need to look into alternatives. – Raffa May 10 '23 at 15:03

1 Answers1

0

now I use

sshpass -f .pass_file ssh dvadmin@$apc '$HOME/.pass_file.sh | sudo -S chmod +x ./.filius_update.sh && ./.filius_update.sh'

and it finally works :) I don't know why my old way doesn't work anymore but I've a solution and now I have to edit my other scripts :/

DonPIZI
  • 11