The short version:
Is there any way to set up automatic public-key-based ssh authentication from one Linux account to two different Github accounts?
You need to create two sets of (public/private) keys, one for each account.
You can reference them through an ssh config file, as detailed in "GitHub: Multiple account setup"/
#Account one
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Users/yourname/.ssh/id_rsa
User git
#Account two
Host ac2.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Users/yourname/.ssh/id_rsa_ac2
User git
It seems GitHub doesn't allow the same RSA key for two repositories.
As workaround, you've to create separate RSA keys for each site:
ssh-keygen -t rsa -f rsa_site1
ssh-keygen -t rsa -f rsa_site2
This will generate private and public keys. Then add public keys into GitHub to Deploy keys.
Then deploy your private keys into the remote:
cat rsa_site1 | ssh user@remote "cat > ~/.ssh/rsa_site1 && chmod 600 ~/.ssh/rsa_site1"
cat rsa_site2 | ssh user@remote "cat > ~/.ssh/rsa_site2 && chmod 600 ~/.ssh/rsa_site2"
And to fetch your private repository on the server, you can use something like:
ssh user@remote 'ssh-agent sh -c '\''cd /webroot/site1 && ssh-add ~/.ssh/rsa_site1 && git fetch git@github.com:priv/site1.git'\'
ssh user@remote 'ssh-agent sh -c '\''cd /webroot/site2 && ssh-add ~/.ssh/rsa_site2 && git fetch git@github.com:priv/site2.git'\'