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/aboriginal/
26 # To trace execution, outcomment next line. Note that emacs input may ...
27 #exec 2>>remote-errors; echo -- >&2; set -x # ... change (no stderr).
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."
61 Note the `0.1` in ssh command line. It is used to avoid any opportunistic
62 behaviour ssh might do; for example if control socket is not alive ssh
63 would attempt to do it's own ssh connection to remote ssh server. As
64 address `0.1` is invalid this attempt will fail early.
68 Easiest way to test this script is to run the pre-made ssh connection
69 using the following command line:
71 ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost sleep 600
73 (replace `[user@]remotehost` with your login info). Doing this the
74 above wrapper script can be run unmodified. After the above command has
75 been run on **one terminal**, enter `chmod +x remote-notmuch.sh` in
76 **another terminal** and then test the script with `./remote-notmuch.sh help`
78 Note that the '~' is inside single quotes for a reason. In this
79 case shell never expand it to `$HOME` -- ssh does it by not reading
80 `$HOME` but checking the real user home directory from `/etc/passwd`.
81 For security purposes this is just how it should be.
85 The path `'~'/.ssh/master-user@host:22` might look too generic to be
86 used as is as the control socket after initial testing (but it can
87 be used). It is presented as a template for what could be configured
88 to `$HOME/.ssh/config`. For example:
91 ControlPath ~/.ssh/master-%h@%p:%r
93 is a good entry to be written in `$HOME/.ssh/config`;
94 [[remoteusage|remoteusage]] uses the same. Now, let's say you'd
95 make your pre-made ssh connection with command
97 ssh -M alice@example.org
100 `readonly SSH_CONTROL_SOCK='~'/.ssh/master-alice@example.org:22`
101 to the `./remote-notmuch.sh` wrapper script testing with
102 `./remote-notmuch.sh help` should work fine.
104 ## Configure Emacs on the client computer ##
106 See the section *Configure Emacs on the client computer* in
107 [[remoteusage|remoteusage]] how to do this. The instructions are the same.
110 ## Creating master connection
112 As mentioned so many times, using this solution requires one pre-made
113 ssh connection in "master" mode. The simplest way is to dedicate one
114 terminal for the connection with shell access to the remote machine:
116 ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost
118 One possibility is to have this dedicated terminal in a way that the
119 connection has (for example 1 hour) timeout:
121 ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost sleep 3600
123 The above holds the terminal. The next alternative puts the command in
126 ssh -f -M -S '~'/.ssh/master-user@host:22 [user@]remotehost sleep 3600
128 If you don't want this to timeout so soon, use a longer sleep, like 99999999
129 (8 9:s, 1157 days, a bit more than 3 years).
131 A more "exotic" solution would be to make a shell script running on remote
132 machine, checking/inotifying when new mail arrives. When mail arrives it
133 could send message back to local host, where a graphical client (to be written)
134 pops up on display providing info about received mail (and exiting this
135 graphical client connection to remote host is terminated).