Had a similar issue trying to connect to my git server
( have a gitea server in a docker container with ssh-port configured to 2022
, instead of standard 22, here as an example my-git-server.lan
).
- create ssh key-pair (quiet, without password)
$ ssh-keygen -q -N '' -b 4096 -f ~/.ssh/mykeyfile
(this will create two files: private-key mykeyfile
and public-key mykeyfile.pub
)
- display contents of the public-key and copy/paste it to your profile's SSH keys in your git-server (similar to how you would do it on Github )
$ cat ~/.ssh/mykeyfile.pub
- add following lines to ssh-config to specify git-server's hostname, port and key-file
$ nano ~/.ssh/config
Host my-git-server.lan
HostName my-git-server.lan
User git
Port 2022
IdentityFile ~/.ssh/mykeyfile
(notice that the username is always git
, regardless of your actual username on your git-server)
- test ssh connection to your git-server using public-key, .. and receive a success message
$ ssh -T git@my-git-server.lan
(again, notice that the username is always git
)
- specify your remote address
ssh://git@my-git-server.lan:2022/alex/myproject.git
for your local git repository (again, notice the user git and the port 2022), .. check remote configuration
$ cd your/local/git/repository/folder
$ git remote add my-git-server ssh://git@my-git-server.lan:2022/alex/myproject.git
$ git remote -v
( here you also see that on my git-server my actual user is alex and repository is myproject )
Done! You can now work with your git-server .. fetch/commit/push etc.