I've only just noticed that you're checking for the exit code to be 1. The only successful error code is 0, so anything else points to an error. In this specific case, GitHub is saying that it doesn't allow shell access. Using 1 for the exit code is appropriate as given the ssh command, one would expect a TTY. I think this is more robust:

```sh
github_ssh_connection="$(ssh -Aq -o BatchMode=yes -o ConnectTimeout=1 git@github.com 2>&1)"

if [[ $github_ssh_connection =~ "successfully authenticated" ]]
then
  # ...
fi
```

[The command explained.](http://explainshell.com/explain?cmd=ssh+-Aq+-o+BatchMode%3Dyes+-o+ConnectTimeout%3D1+git%40github.com+2%3E%261).