Page 1 of 1

SFTP from Mister script not working

Posted: Sat Feb 11, 2023 10:24 pm
by richard.fox

Hello all. I'm in the process of trying to write a shell script for use from my Mister that will automatically transfer files from the SD card to a web server that I own. The server only allows connections via key pair, username/password authentication is disabled. I've got my key pair generated and the server is set up to allow them. I know they are correct because I can ssh into the mister and run the script from the command line:

./sftp_script.sh

and it authenticates properly and starts an sftp session. When I try to run the script from the mister UI, however:

System Settings->Scripts->sftp_script

I get a "Permission denied (publickey)" error. So there is something specific about running from the mister UI that is causing problems. I'm wondering if there are any linux and or mister gurus who can help me figure out what is going on. It looks like the script is run by the root user, same as when I run it when ssh'd in to the mister. I've checked file permissions, server logs and every stack overflow article I can find. Any help would be greatly appreciated. I'll attach the script itself as well as the error from the verbose command output.

Error:
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Server accepts key: /root/.ssh/id_rsa
debug1: read_passphrase: can't open /dev/tty: No such device or address
debu1: No more authentication methods to try
Permission denied (publickey).
Connection closed


Re: SFTP from Mister script not working

Posted: Sun Feb 12, 2023 4:24 am
by wellbow
richard.fox wrote: Sat Feb 11, 2023 10:24 pm

debug1: read_passphrase: can't open /dev/tty: No such device or address
debu1: No more authentication methods to try
Permission denied (publickey).
Connection closed

Does your ssh keypair have a passphrase? If so, that may be causing problems.

Might be easier to pull files from the MiSTer than try to push them, for example:

Code: Select all

sshpass -p1 scp -p root@$MISTER_HOSTNAME:/media/fat/names.txt .

Re: SFTP from Mister script not working

Posted: Sun Feb 12, 2023 5:16 am
by richard.fox

Yes, the key does have a passphrase. I will try to set one up without. Any idea why that would cause problems when I run from the UI vs from ssh command line? Also, the mister only gives me the internal network ip. It would be difficult to find/supply any external ip on the fly in order to pull from the server.


Re: SFTP from Mister script not working

Posted: Sun Feb 12, 2023 6:46 pm
by wellbow

The error I quoted is saying that /dev/tty does not exist. it does exist when you SSH into Linux. I suspect that when run from the menu, the environment is different.

SSH (and sftp) want to be able to directly interact with the terminal in order to make it more likely that a human is entering the passphrase in a manner that can't be snooped on by another process.


Re: SFTP from Mister script not working

Posted: Sun Feb 12, 2023 7:07 pm
by Bas

A script doesn't have keyboard input available (tty). Use keys without passphrase.


Re: SFTP from Mister script not working

Posted: Fri Mar 10, 2023 8:28 pm
by richard.fox

Finally got back around to testing this today. You were correct, the keys can't have a passphrase. Thanks wellbow and Bas for the help, I really appreciate it!