Using Git over SSH on a NAT VPS with a Custom Port
Updated · Autdo Cloud
Git can use SSH through an assigned NAT port. For a custom port, use an explicit ssh:// remote URL or an SSH configuration alias; the common user@host:path syntax does not contain a port field.
An SSH alias
On your local computer, adapt:
Host my-nat-vps
HostName PUBLIC_HOST
Port PUBLIC_PORT
User git
IdentityFile ~/.ssh/autdo_vps
IdentitiesOnly yes
sshconfig
The placeholders must be replaced, and the remote user and repository must already exist with appropriate permissions. Test ssh my-nat-vps before troubleshooting Git. A restricted Git account may reject an interactive shell even when repository access is correct.
An explicit remote can look like ssh://git@PUBLIC_HOST:PUBLIC_PORT/srv/git/project.git. With the alias, a remote can be my-nat-vps:/srv/git/project.git.
Keep access narrow
Use a dedicated account and deliberate repository permissions. Do not reuse a privileged administrator key for every deployment if a narrower deploy key will do. Verify host identity before trusting a new endpoint.
Protect the repository
A repository is not a secret manager. Avoid committing credentials, production data or private keys. Back up repositories independently and test that another authorized operator can recover them. For a team needing reviews, access auditing and availability, compare a dedicated Git hosting service rather than assuming raw SSH storage provides those features.
See SSH keys, NAT SSH access and backup design.
Reference: Git protocol documentation.