SFTP from Mister script not working

Kernel, Main, Utilities & Applications, Miscellaneous Devices.
richard.fox
Posts: 3
Joined: Sat Feb 11, 2023 10:03 pm

SFTP from Mister script not working

Unread post 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

Attachments
sftp_script.log
(436 Bytes) Downloaded 89 times
wellbow
Posts: 5
Joined: Fri Oct 14, 2022 6:39 am

Re: SFTP from Mister script not working

Unread post 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 .
richard.fox
Posts: 3
Joined: Sat Feb 11, 2023 10:03 pm

Re: SFTP from Mister script not working

Unread post 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.

wellbow
Posts: 5
Joined: Fri Oct 14, 2022 6:39 am

Re: SFTP from Mister script not working

Unread post 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.

Bas
Top Contributor
Posts: 518
Joined: Fri Jan 22, 2021 4:36 pm
Has thanked: 60 times
Been thanked: 225 times

Re: SFTP from Mister script not working

Unread post by Bas »

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

richard.fox
Posts: 3
Joined: Sat Feb 11, 2023 10:03 pm

Re: SFTP from Mister script not working

Unread post 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!

Post Reply