1 ## Remoteusage without password-free login requirement
3 This is alternative to [[remoteusage|remoteusage]] where password-free
4 login is not a requirement. See [[remoteusage|remoteusage]] page for
5 other requirements and general information.
7 This solution uses one pre-made ssh connection where the client is put
8 into "master" mode (-M) for connection sharing. The wrapper script then
9 uses the control socket created by this pre-made ssh connection for
10 its own connection. As long as master ssh connection is live, slave
11 can use it. Disconnecting master all future attempts to connect
12 from the script will fail.
14 At the end of this document there is information for some possible ways
15 how master ssh connection can be done.
19 Write the following code to a file, for example `remote-notmuch.sh`.
23 # http://notmuchmail.org/remoteusage/124/
26 # To trace execution, uncomment next line.
27 #BASH_XTRACEFD=6; exec 6>>remote-errors; echo -- >&6; set -x
29 readonly SSH_CONTROL_SOCK='~'/.ssh/master-user@host:22
31 readonly notmuch=notmuch
33 printf -v ARGS '%q ' "$@" # bash feature
35 readonly SSH_CONTROL_ARGS='-oControlMaster=no -S '$SSH_CONTROL_SOCK
37 if ssh -q $SSH_CONTROL_ARGS 0.1 $notmuch $ARGS
42 # continuing here in case ssh exited with nonzero value.
45 'config get user.primary_email') echo 'nobody@nowhere.invalid'; exit 0 ;;
46 'config get user.name') echo 'nobody'; exit 0 ;;
47 'count'*'--batch'*) while read line; do echo 1; done; exit 0 ;;
48 'count'*) echo 1; exit 0 ;;
49 'search-tags'*) echo 'errors'; exit 0 ;;
50 'search'*'--output=tags'*) echo 'errors'; exit 0 ;;
53 if ssh $SSH_CONTROL_ARGS -O check 0.1
55 echo ' Control socket is alive but something failed during data transmission.'
59 echo " See`sed '1d;2d;s/.//;q' "$0"` for help."
62 Note the `0.1` in ssh command line. It is used to avoid any opportunistic
63 behaviour ssh might do; for example if control socket is not alive ssh
64 would attempt to do it's own ssh connection to remote ssh server. As
65 address `0.1` is invalid this attempt will fail early.
69 Easiest way to test this script is to run the pre-made ssh connection
70 using the following command line:
72 ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost sleep 600
74 (replace `[user@]remotehost` with your login info). Doing this the
75 above wrapper script can be run unmodified. After the above command has
76 been run on **one terminal**, enter `chmod +x remote-notmuch.sh` in
77 **another terminal** and then test the script with
79 ./remote-notmuch.sh help
81 Note that the '~' in the ssh command line above is inside single quotes
82 for a reason. In this case shell never expand it to `$HOME` -- ssh does
83 it by not reading `$HOME` but checking the real user home directory
84 from `/etc/passwd`. For security purposes this is just how it should
89 The path `'~'/.ssh/master-user@host:22` might look too generic to be
90 used as is as the control socket after initial testing (but it can
91 be used). It is presented as a template for what could be configured
92 to `$HOME/.ssh/config`. For example:
95 ControlPath ~/.ssh/master-%h@%p:%r
97 is a good entry to be written in `$HOME/.ssh/config`;
98 [[remoteusage|remoteusage]] uses the same. Now, let's say you'd
99 make your pre-made ssh connection with command
101 ssh -M alice@example.org
104 `readonly SSH_CONTROL_SOCK='~'/.ssh/master-alice@example.org:22`
105 to the `./remote-notmuch.sh` wrapper script testing with
106 `./remote-notmuch.sh help` should work fine.
108 ## Configure Emacs on the client computer ##
110 See the section *Configure Emacs on the client computer* in
111 [[remoteusage|remoteusage]] how to do this. The instructions are the same.
114 ## Creating master connection
116 As mentioned so many times, using this solution requires one pre-made
117 ssh connection in "master" mode. The simplest way is to dedicate one
118 terminal for the connection with shell access to the remote machine:
120 ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost
122 One possibility is to have this dedicated terminal in a way that the
123 connection has (for example 1 hour) timeout:
125 ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost sleep 3600
127 The above holds the terminal. The next alternative puts the command in
130 ssh -f -M -S '~'/.ssh/master-user@host:22 [user@]remotehost sleep 3600
132 If you don't want this to timeout so soon, use a longer sleep, like 99999999
133 (8 9:s, 1157 days, a bit more than 3 years).
135 A more "exotic" solution would be to make a shell script running on remote
136 machine, checking/inotifying when new mail arrives. When mail arrives it
137 could send message back to local host, where a graphical client (to be written)
138 pops up on display providing info about received mail (and exiting this
139 graphical client connection to remote host is terminated).
143 If you experience strange output when using from emacs first attempt to just
146 ./remote-notmuch.sh help
148 from command line and observe output. If it looks as it should be next uncomment
151 #BASH_XTRACEFD=6; exec 6>>remote-errors; echo -- >&6; set -x
153 in `./remote-notmuch.sh` and attempt to use it from emacs again -- and then
154 examine the contents of `remote-errors` in the working directory emacs was