Linux

Git remote add or set url on custom SSH port

Sometimes we need to change SSH port on git server, because client is behind firewall or for security reasons.

For example, git server ssh run on port 443.

So we need to add or set url to non standard port.

Git remote add on custom SSH port

To add remote origin, we can use this command:

# cd /path/to/directory
# git remote add origin ssh://git@gitlab.yourserver.com:443/root/www.serverdiary.com.git
# git add .
# git commit -m "Initial commit"
# git push -u origin master

Git remote set url custom SSH port

But if you have already add push / fetch git url, you can follow this steps.

First, check remote push and fetch url using this command:

# cd /path/to/directory
# git remote -v
# origin  git@yourserver.com:root/www.serverdiary.com.git (fetch)
# origin  git@yourserver.com:root/www.serverdiary.com.git (push)

Then use this command to update / replace your git remote url.

# cd /path/to/directory
# git remote set-url origin ssh://git@gitlab.yourserver.com:443/root/www.serverdiary.com.git
# git add .
# git push -u origin master

Hope this helps.

Recent Posts

How to fix yum update error thread.error: can’t start new thread

If you found error thread.error: can't start new thread on yum update command on CentOS…

5 months ago

How to securing Cockpit login with Google Two Factor Authenticator 2FA

Cockpit is a web-based graphical interface for servers, intended for everyone, especially those who are:…

8 months ago

How to install Cockpit on CentOS 7 / CentOS 9 Stream and configure Nginx reserve proxy

From cockpit-project.org, Cockpit is a web-based graphical interface for servers, intended for everyone, especially those…

10 months ago

How to install and configure Nginx with HTTP3 on CentOS 9 Stream / RHEL 9

We have been using Nginx with HTTP3 for more than 1 year on our production…

11 months ago

How to sync date time using Crony on CentOS 9 Stream / RHEL 9

On CentOS 7, to sync date time we often use NTPD. But on CentOS 9,…

11 months ago

How to install and enable REMI repository on CentOS 9 Stream

Remi repository is one of third-party repository that have latest update of PHP on Enterprise…

11 months ago