Currently, Eshell has a special $UID variable that's connection-aware (so it returns the remote UID if the current directory is remote). However, it doesn't do this for $GID. Here's a patch to fix that.