User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
osx:start [2018/06/15 14:13]
robm [Middle-click via the trackpad]
osx:start [2020/01/30 20:45] (current)
robm [GPG with remote forwarding]
Line 754: Line 754:
 More thorough networking (Ethernet layer, instead of link layer): http://​​2011/​11/​ssh-vpns-bridged-connection-to-lan.html More thorough networking (Ethernet layer, instead of link layer): http://​​2011/​11/​ssh-vpns-bridged-connection-to-lan.html
 +===== Automating via SSH configuration files =====
 +<note important>​All commands here are run as **root** on the client system</​note>​
 +  - **As root** on your client system, generate a new SSH keypair to use for VPN. <​code>​ssh-keygen -f ~/​.ssh/​id_rsa_vpn -N ''</​code>​
 +  - Install new public key into remote system, and prefix with a ForeCommand which is run whenever this key is used to authenticate:<​code>​( \
 +  printf '​tunnel="​0",​command="​ifconfig tun0 inet dstaddr"​ ' ; \
 +  cat ~/​.ssh/​ \
 +) | ssh tee -a .ssh/​authorized_keys</​code>​
 +  - Configure client via ''​~/​.ssh/​config''​. Add the following to the end of ''​.ssh/​config''​ (create it if it does not exist) and replace ''​$SERVER''​ with your server'​s hostname: <​code>​Host vpn
 +  Hostname $SERVER
 +  User root
 +  # Remote'​s .ssh/​authorised_keys entry for this identity is prefixed with:
 +  # tunnel="​0",​command="​ifconfig tun0 inet dstaddr"​ ssh-rsa
 +  IdentityFile ~root/​.ssh/​id_rsa_vpn
 +  Tunnel yes
 +  TunnelDevice 0:0
 +  PermitLocalCommand yes
 +  LocalCommand ~root/​.ssh/​ %h %T
 +  # Disable connection sharing, otherwise closing VPN may not actually reset
 +  # network settings because (cf. LocalCommand) continues to wait
 +  # for the `ssh` process to exit (which it may not if another session is
 +  # active)
 +  ControlPath none
 +  # Disable use of ssh-agent, as it seems to prevent our preferred identity
 +  # (cf. IdentityFile) being applied, which in turn means we don't trigger the
 +  # ForceCommand of the remote'​s authorized_keys file
 +  IdentityAgent none</​code>​
 +  - Create a new script on your client machine at ''​~root/​.ssh/​''​ which configures your Mac to route traffic headed to your server via the current gateway, and then change the default gateway (that applies to all __other__ traffic) to go via the new SSH ''​tun''​ device at, then wait for the ''​ssh''​ process to exit before returning settings to normal: <​code>#​!/​bin/​bash
 +# .ssh/​config:​ LocalCommand %h %T
 +ifconfig $TUNNEL_DEVICE inet
 +ROUTE=$(route get $REMOTE_HOST)
 +GATEWAY=$(sed -ne 's/^ *gateway: //p' <<<"​$ROUTE"​)
 +INTERFACE=$(sed -ne 's/^ *interface: //p' <<<"​$ROUTE"​)
 +route add 10/8 $GATEWAY
 +route change default
 +while kill -0 $WAIT_PID >/​dev/​null 2>&​1;​ do sleep 0.5; done
 +# The route gets deleted when the SSH tunnel closes gracefully and tun0 disappears
 +route change default $GATEWAY
 +route add default $GATEWAY
 +route delete 10/8 $GATEWAY
 +route delete $REMOTE_HOST $GATEWAY
 +) &</​code>​ This script is unlikely to work on other OS
 +  - Make the new script executable: <​code>​chmod a+x ~root/​.ssh/​</​code>​
 +  - Test it by running <​code>​ssh vpn</​code>​
 +Sample session showing the output from the commands above:
 +# ssh-keygen -f ~/​.ssh/​id_rsa_vpn -N ''​
 +Generating public/​private rsa key pair.
 +Your identification has been saved in /​var/​root/​.ssh/​id_rsa_vpn.
 +Your public key has been saved in /​var/​root/​.ssh/​
 +The key fingerprint is:
 +SHA256:​4c8jh23lnMr7ZEmiDCCenKEEo6ROBDIku3XCmKLqqcw root@roberts-mbp
 +The key's randomart image is:
 ++---[RSA 2048]----+
 +|X+               |
 +|OB               |
 +|Bo* o   ​. ​       |
 +|** B . . .       |
 +|+.=   . S . o    |
 +|.      o * * o   |
 +|.       = B B    |
 +|+ .      = =     |
 +|oE        +o.    |
 +# ( \
 +#   ​printf '​tunnel="​0",​command="​ifconfig tun0 inet dstaddr"​ ' ; \
 +#   cat ~/​.ssh/​ \
 +# ) | ssh tee -a .ssh/​authorized_keys
 +tunnel="​0",​command="​ifconfig tun0 inet dstaddr"​ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+pPee+HqiExk28lwKGcjoAMnkWRVKoQsn8b+90ST3HteZq1oCKtig49YOtlXDZGma0vR/​y9Xbelk26xJfZO32BR3GCPou6XYSU67qwC8wK256H0LfTUlquUufklmKd3BaKamAtXU0JwhVxQCFH0hToG6dgc0FLelqs1r8u6cPni1wTxaId6epHrYCBrKvP+fwYz0S0K3e2opcqZUTwMyPYwu280UxQr2HYvzykdoJeiJtsKgneFRxhX7gnlKCYoia0fToKHel24GfUFfqipFrJbsm8LDYuVh5KVgx1J1Hx19Fu0LM3IIqoXQESob91TjTx1bq41iIMZ0n0td5gDVj root@roberts-mbp
 +# ssh vpn
 +add host​ gateway
 +add net 10: gateway
 +change net default: gateway
 +# Nothing further appears to happen. VPN is up and running! Try `traceroute
 +#` in another terminal to verify that the traffic is going via your
 +# server and not its default route.
 +# When all done, press ^C to kill the VPN and restore default settings. Your
 +# prompt will return first, and *then* the clean-up code will execute and
 +# print:
 +route: writing to routing socket: not in table
 +change net default: gateway not in table
 +add net default: gateway
 +delete net 10: gateway
 +delete host​ gateway
 ====== Global Keyboard Shortcut to toggle Skype microphone ====== ====== Global Keyboard Shortcut to toggle Skype microphone ======
Line 804: Line 904:
   brew cask install smcfancontrol   brew cask install smcfancontrol
 +====== GPG with remote forwarding ======
 +GPG Agent forwarding allows a remote system to access secrets held in your local system via an SSH tunnel. When you are not connected to the remote system, it cannot access your secrets, and if the remote system is compromised your secrets are not (since they are never stored on it).
 +My (initial) use-case is to allow docker on a remote host to store login my login credentials (so I can push/pull images when working), but not store secrets on that hose. THe default behaviour is to store my password in plain text, which is unacceptable.
 +So I opted to use [[https://​​engine/​reference/​commandline/​login/#​credentials-store|docker credentials management]] and [[https://​​|pass]]. The ''​pass''​ tool uses GPG to encrypt and decrypt passwords. If I use GPG the traditional way (with secret keys in my $HOME directory) I've not gained any security: the encrypted password and and the decryption key are on the same host!
 +So I want to use GPG agent forwarding to allow ''​pass''​ to decrypt secrets while I am connected and working, without the decryptions keys ever leaving my laptop.
 +Overview (notes to follow, I hope):
 +  - Install GPG locally and create an identity
 +  - Ensure that passphrase challenge ("​pinentry"​) does _not_ use the TTY, since the TTY at the remote won't match local - better to use a GUI or the OSX KeyChain
 +  - Install GPG on remote, and import public key
 +  - Configure SSH to forward agent socket
 +  - Disable systemd stuff which creates (unused) gpg sockets and/or configure SSHd to allow you to delete and recreate those sockets
 +Gotchas to document:
 +Invalid ioctl for device means the GPG agent was attempting to open a TTY. The agent lives on my MacBook, but the request comes from a remote system. So the remote system'​s GPG_TTY value is utterly useless on my MacBook, hence the error. Pinentry is the method by which the end-user (me) is prompted to enter a passphrase of the decryption key, the default is TTY, which doesn'​t work in this scenario. Using a GUI based one (line pinentry-mac) solves this, since the GUI always pops up on my Macbook.
 +  - ''​brew install gnupg gpg-agent pinentry-mac''​
 +  - Append to ''​~/​.profile'':​ <​code>​ if [ -f ~/​.gnupg/​.gpg-agent-info ] && [ -n "​$(pgrep gpg-agent)"​ ]; then
 +    source ~/​.gnupg/​.gpg-agent-info
 +    export GPG_AGENT_INFO
 +    eval $(gpg-agent --daemon --write-env-file ~/​.gnupg/​.gpg-agent-info)
 +  - Create/​modify the following GPG files:
 +    - ''​mkdir -p ~/​.gnupg''​
 +    - ''​~/​.gnupg/​gpg.conf'':<​code>​use-agent</​code>​
 +    - ''​~/​.gnupg/​gpg-agent.conf'':<​code>​ use-standard-socket
 +pinentry-program /​usr/​local/​bin/​pinentry-mac
 +default-cache-ttl 600
 +max-cache-ttl 7200</​code>​
 +<​code>​echo "​foo"​ | gpg --encrypt -r "​Robert Meerman"​ | gpg --decrypt</​code>​
 +Remote end:
 +Modify ''/​etc/​ssh/​sshd_config''​ to include:
 +# Allow socket files to be unlinked by incoming connections (intended to
 +# faciliate use of GPG Agent)
 +StreamLocalBindUnlink yes
 +See https://​​AgentForwarding
 +Client: ''​gpg -K''​ to show secret (private) keys. Take the HEX (public key fingerprint) and ...
 +Server: ''​gpg --recv-key 6F840EE9A203D5283CAA943EF07529A9FE85C329''​
 +.. and trust it, or tools like '​passwd'​ cannot use it:
 +Server: ''​gpg --edit-key "​Robert Meerman"''​ and then enter ''​trust''​ and set to ''​Ultimate''​ (it's your own key after all), then ''​quit''​.
 +Server testcase: <​code>​echo "​foo"​ | gpg --encrypt -r "​Robert Meerman"​ | gpg --decrypt</​code>​
 +====== Number Pad ======
 +I installed an application to make my iPhone act as a Number Pad: https://​​gb/​app/​remote-keypad-numpad-keyboard/​id1135300319
 +Satisfies [[https://​​q/​108249/​20696|Blender'​s obsession]] with number pads!
osx/start.1529072035.txt.gz · Last modified: 2018/06/15 14:13 by robm