Using Other Unix User to Authenticate in SSH

2025-02-24

There are some code that I need version tracking, but are placed in /root or some user-inaccessible directory, so it would be natural to use root when creating, and updating the git repo.

However, to upload your repo to GitHub, you can only use your ssh keys. For the sake of security, I don't want to use root for ssh-ing, so, It would make sense to su to some other users while ssh-ing, here's how I did it.

env HOME=/home/<user> SSH_TTY=$TTY SSH_AUTH_SOCK=/run/user/<user_uid>/ssh-agent.socket git push

<user> is the username that you have ssh access to, and <user_uid> is the UID of that user, usually 1000 for a personal computer.

Breakdown: