Timeout not working for SSHFS connection in script

Viewed 10

I want to automate a sftp-based backup in a alpine-based docker container. I've got a /bin/sh script that should check if the connection is established successfully. Clients connect via ssh keys, so it is passwordless authentication.

timeout -k 1 4 sshfs -p $port -o IdentityFile=/home/ssh/ssh_host_rsa_key,StrictHostKeyChecking=accept-new,_netdev,reconnect $user@$address:/ /mnt/sftp/

This line establishes the sftp connection. It works just fine if the key is correct and even when the server is refusing the connection. But there is a problem when the server isn't accepting the key provided, then it's asking for a password in the interactive shell like: user123@backup.example.xyz's password: and timeout just does not kill the process, the script doesn't go foroward after this since it waits for user input (which is not going to happen).

I use this script at startup to check the connection and stop the container immediately if it fails, so the user notices configuration errors right as he starts the container.

Is there a way to kill this command after a certain time or as a workaround prohibit interactive input for the sshfs command?

Thanks!

0 Answers
Related