Monday, December 26, 2022

GPT as a learning tool

I've really liked using GPT as a tutor. I recently needed to learn about SSO/SAML2, and it was such a luxury to be able to pose questions to GPT, and in particular to be able to express my understanding of the protocol and have GPT either confirm or correct it. I think it is pretty clear that this capacity to evaluate our expressed understanding of a concept is going to really accelerate our learning.

Normally when I learn some new concept online, I spend a lot of extra time with supplementary reading looking to confirm or disprove a model of that concept in my mind. But In this case with GPT I could skip this step and just summarize what I thought I knew about the topic and ask GPT to compare what I was saying with its own understanding.

I also really like the ability of GPT to confirm whether a given technique in an engineering implementation is common. I think a lot of the problem of managing risk in an engineering project is to try to keep your integration points on the beaten path, i.e., it is best to structure how you connect to shared tools such that these connections are consistent with the way other users are using the tool; this way you are more likely to be in line with the design and less subject to surprises -- and you are less likely to be caught out with an awkward upgrade path as the software evolves.

Friday, September 9, 2022

Running ssh tunneled X clients after su

When you ssh to a machine and then run an X client, the authentication is based on having a valid entry in your ~/.XAuthority file, which your ssh client intializes automatically if you run ssh with -X or -Y. But if you su to be another user, that authorization cannot be found, and the X client initiailization will fail.

To manage this situation, I wrote a pair of scripts and aliases. X.auth_save saves the authentication away to /tmp:

  
#!/bin/bash
. X.auth_saved.inc
auth=`xauth -f $HOME/.Xauthority list | tail -1`
echo $auth > $x_auth_saved
chmod 777    $x_auth_saved
echo "Saved X authority $auth to $x_auth_saved"

Restore as a new user with X.auth_restore:
#!/bin/bash
. X.auth_saved.inc
if [ -r $x_auth_saved ]; then
        echo "OK found \"$x_auth_saved\"" 1>&2
else
        echo "FAIL could not find \"$x_auth_saved\"" 1>&2
        exit 1
fi
auth=`cat $x_auth_saved`
echo "Restored X authority $auth from $x_auth_saved"
touch $HOME/.Xauthority
if ! xauth add $auth; then
        echo "FAIL: xauth add $auth failed, exiting..." 1>&2
        exit 1
else
        echo "OK xauth add $auth"
fi

Lastly track the shared file variable name in X.auth_saved.inc:
x_auth_saved=/tmp/X.auth_saved
Since the names are unwieldy, I aliased them to xas and xar:
alias xas=X.auth_save
alias xar=X.auth_restore