0

On my server with the ip 192.168.142.200 I have a simple bash script (for testing purposes) /etc/custom/scriptOnServer:

#!/bin/bash
echo -e "$1\n$1" | veracrypt -t -k "" --pim=1 --protect-hidden=no /dev/sdi1 /mnt/ggg
echo
echo "...and now get rid of the crypts..."
echo
echo -e "$1" | veracrypt -d /dev/sdi1

The script mounts an encrypted veracrypt partition and unmounts it and works just fine, when invoked on the server with the right input parameter $1. (This parameter has to be the user password, which has to be the same as the veracrypt password. The user has sudo priviledges.)

/bin/bash /etc/custom/scriptOnServer PASSWORD

If I call the script from another machine (which I will call client) via ssh with sshpass without X11 forwarding, the scriptOnServer works fine, too. The last line of the script passes the needed password for the veracrypt unmount to it. I have another script on the client to do that:

#!/bin/bash
pw=$(zenity --password --title=Insert password)
sshpass -p $pw ssh $USER"@"192.168.142.200 /bin/bash /etc/custom/scriptOnServer $pw

On the client I have a running X-session and use zenity to type in the password.

BUT, if I use X11 forwarding like so

#!/bin/bash
pw=$(zenity --password --title=Insert password)
sshpass -p $pw ssh -X $USER"@"192.168.142.200 /bin/bash /etc/custom/scriptOnServer $pw

the unmounting of the veracrypt partition does not work without entering the password again. Funnily, on the client machine, a neat window plops up, kindly asking me: "Enter your user password or administrator password:". Apparently, the last line of the scriptOnServer does not pass the password into the stdin of veracrypt.

How can I use ssh (with sshpass) in a client script that allows X11 forwarding without having to enter the password a second time?

On both computers (server and client) I have a debian 9 stretch running. The client has a fully installed X11 - on the server I only installed the minimum, just so X11 forwarding can be done over ssh to a requesting client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.