This is probably not a dup; I have read through many similar problems on StackOverflow but not this issue.
I am trying to use multiple git accounts on Ubuntu Linux a
This happens because ssh-agent caches the ssh key (you can even remove the file and it will still allow ssh to connect successfully until the cache is cleared) and will prioritise the cached keys even over the ones specified via IdentityFile. You can see which files are cached by running:
ssh-add -l
You can force ssh-agent to ignore the cache by including IdentitiesOnly "yes" in the .ssh/config for each connection:
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_dsa_work
IdentitiesOnly yes
More information here: http://sealedabstract.com/code/github-ssh-with-multiple-identities-the-slightly-more-definitive-guide/
It took me quite a while to discover this too, hope it helps someone.