Thursday, February 7, 2019

Emacs Tramp and GCP

source

In order to get Emacs Tramp to work nicely with gcp's ssh'ing mechanism, some scripts and configurations need to be made.

gssh:

#!/bin/bash
HOST="$1"
if [[ $HOST = *"@"* ]] ; then
USER=$(echo $HOST | cut -d'@' -f1)
HOST=$(echo $HOST | cut -d'@' -f2)
fi
gcloud config list | grep 'Your active'
ZONE=$(gcloud compute instances list |grep -E "^$HOST[[:space:]]" | awk '{print $2}')
echo zone: $ZONE
gcloud compute ssh --zone=$ZONE "$@"

Once that is set, edit .emacs and add a configuration for Tramp to use gssh:
;; TRAMP gcloud ssh
(add-to-list 'tramp-methods
'("gssh"
(tramp-login-program "gssh")
(tramp-login-args (("%h")))
(tramp-async-args (("-q")))
(tramp-remote-shell "/bin/sh")
(tramp-remote-shell-args ("-c"))
(tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
("-o" "UserKnownHostsFile=/dev/null")
("-o" "StrictHostKeyChecking=no")))
(tramp-default-port 22)))

Done.

No comments:

Post a Comment