Sunday, June 7, 2026

GIT HTTP to SSH

 

[root@localhost ~]# cd devops1

[root@localhost devops1]# ls

index.php  storage  test1.html  test2.html

[root@localhost devops1]# git status

On branch dummy

Your branch is up to date with 'origin/dummy'.

 Untracked files:

(use "git add <file>..." to include in what will be committed)

test2.html

 [root@localhost devops1]#  git remote show

origin

[root@localhost devops1]#  git remote show  origin

 Click cancel

error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass'

Username for 'http://gitlab.reposerver.com': centos

error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass'

Password for 'http://centos@gitlab.reposerver.com':

* remote origin

  Fetch URL: http://gitlab.reposerver.com/centos/mysecondproject.git       --> project URL

  Push  URL: http://gitlab.reposerver.com/centos/mysecondproject.git

  HEAD branch: main

  Remote branches:

    dummy tracked

    main  new (next fetch will store in remotes/origin)

  Local branch configured for 'git pull':

    dummy merges with remote dummy

  Local ref configured for 'git push':

    dummy pushes to dummy (up to date)

[root@localhost devops1]# git status

On branch dummy

Your branch is up to date with 'origin/dummy'.

 Untracked files:

(use "git add <file>..." to include in what will be committed)

 test2.html

nothing added to commit but untracked files present (use "git add" to track)

[root@localhost devops1]# git add test2.html

[root@localhost devops1]# git commit -m "HTTP to SSH key"

[dummy 4de716e] HTTP to SSH key

 1 file changed, 1 insertion(+)

 create mode 100644 test2.html

 

[root@localhost devops1]# git status

On branch dummy

Your branch is ahead of 'origin/dummy' by 1 commit.

  (use "git push" to publish your local commits)

nothing to commit, working tree clean

 [root@localhost devops1]# git branch

* dummy

[root@localhost devops1]# git status

On branch dummy

Your branch is ahead of 'origin/dummy' by 1 commit.

  (use "git push" to publish your local commits)

 nothing to commit, working tree clean

[root@localhost devops1]# git push origin dummy
error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass'
Username for 'http://gitlab.reposerver.com': centos
error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass'
Password for 'http://centos@gitlab.reposerver.com':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 278 bytes | 278.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for dummy, visit:
remote:   http://gitlab.reposerver.com/centos/mysecondproject/-/merge_requests/new?merge_request%5Bsource_branch%5D=dummy
remote:
To http://gitlab.reposerver.com/centos/mysecondproject.git
   2b10a63..4de716e  dummy -> dummy

[root@localhost devops1]# git status

On branch dummy

Your branch is ahead of 'origin/dummy' by 1 commit.

  (use "git push" to publish your local commits)

nothing to commit, working tree clean

 

[root@localhost devops1]# git branch

* dummy

[root@localhost devops1]# git status

On branch dummy

Your branch is ahead of 'origin/dummy' by 1 commit.

  (use "git push" to publish your local commits)

 

nothing to commit, working tree clean

 

Then,

Browse the URl  gitlab.reposerver.com

 
 Click admin and then preferences

 

 

Click access then SSH keys, click Add new key

 

To generate key

[root@localhost devops1]# cd

[root@localhost ~]# cd ..ssh

-bash: cd: ..ssh: No such file or directory

[root@localhost ~]# ls -al

total 10592

-rw-r--r--   1 root root    1009 Jun  1 16:51 server.csr

-rw-r--r--   1 root root      31 Jun  6 13:07 shell1.sh

No ssh folder

[root@localhost ~]# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):           -àEnter

Created directory '/root/.ssh'.

Enter passphrase (empty for no passphrase):                     àenter

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:23oRSb5KUByyAcc8naTj3n4dT7NCLean8Xnkyyv1syg root@localhost.localdomain

The key's randomart image is:

+---[RSA 3072]----+

|    .+++oo       |

|     .+== .      |

|      +o o .     |

|     ...  +      |

|      ..S  o .   |

|     . ..oo = +..|

|      ..o..*.=.=.|

|       ...oE++*o+|

|        oo  o=+*=|

+----[SHA256]-----+

 

[root@localhost devops1]# cd /root/.ssh/

[root@localhost .ssh]# ls

id_rsa  id_rsa.pub

[root@localhost devops1]# cd /root/.ssh/

[root@localhost .ssh]# ls

id_rsa  id_rsa.pub

[root@localhost .ssh]# cat id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDu1BgOZm9qGig/qu6bwOQIh2X7SwD8fKQGTF36RjmBIN8WKsCsV1NWkKphAC51CTiUJPGpOfjuNXAoVwaeg2nrrsfw0ZZpfStRdePNaPfmdxrv/mpypsrJ1fJ+kGth7nU26Bnz/ZQEKFLQjDkkLQDqXJBiB+XHtVBjBNh//o6lnyredkkaMpk5aBwh1tJ72VHKY2P581NnEeDp+oEe2UVViXpu++929kfIZuvvSVRAQJ1MFB8OnshOzcmzhr+vCi0iE0JX/qwW6P9Vf0IPeaCsfmvFMVEde4ZVgrCHDeIKPQnnkDVqdhJFztXyd9fyPEjSXuiwsVyfvlLO1wTFgCCf94mFOM7HoHRxT7jslGpcKc2sdixaPlgrB1MjodhrlkJ9cijusI5aIlkJDhNSPk9VBfM4iTrQriWQugX5c7PctiKIvgp9O1MCUgggRzAZvjt2MG4YLYA22Fagx7Ikn9VY9cx/0kAdvcRWGIbhq/+YQG7wgDtxIVUfkXuiHO8y1yc= root@localhost.localdomain

Then paste ssh key to key

 Click on home page to go to own project

 

Then, projects…….click Personal…click on URL centos/mysecondproject

 

Click code…then copy URL SSH

 

 

[root@localhost .ssh]# cd ..

[root@localhost ~]# cd devops1

[root@localhost devops1]# ls

index.php  storage  test1.html  test2.html

[root@localhost devops1]# git remote show origin

error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass'

Username for 'http://gitlab.reposerver.com': centos

error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass'

Password for 'http://centos@gitlab.reposerver.com':

* remote origin

  Fetch URL: http://gitlab.reposerver.com/centos/mysecondproject.git

  Push  URL: http://gitlab.reposerver.com/centos/mysecondproject.git

  HEAD branch: main

  Remote branches:

    dummy tracked

    main  new (next fetch will store in remotes/origin)

  Local branch configured for 'git pull':

    dummy merges with remote dummy

  Local ref configured for 'git push':

    dummy pushes to dummy (up to date)

Remove origin

[root@localhost devops1]# git remote remove origin

[root@localhost devops1]# git remote show

[root@localhost devops1]# cd /root/.ssh/

[root@localhost .ssh]# git push origin dummy

fatal: not a git repository (or any of the parent directories): .git

[root@localhost .ssh]# git remote add origin git@gitlab.reposerver.com:centos/mysecondproject.git

fatal: not a git repository (or any of the parent directories): .git

Solution

[root@localhost devops1]# git remote add origin git@gitlab.reposerver.com:centos/mysecondproject.git

[root@localhost devops1]# git push origin dummy

The authenticity of host 'gitlab.reposerver.com (192.168.184.130)' can't be established.

ECDSA key fingerprint is SHA256:o+usCrHII081QvyR0ZYge7pyJHhjDDk5OSf8gfSaM7k.

Are you sure you want to continue connecting (yes/no/[fingerprint])?yes

git@gitlab.reposerver.com's password:

Permission denied, please try again.

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

 [root@localhost devops1]# ssh git@gitlab.reposerver.com

git@gitlab.reposerver.com's password:

 [root@localhost devops1]# ssh -p 2222  git@gitlab.reposerver.com

The authenticity of host '[gitlab.reposerver.com]:2222 ([192.168.184.130]:2222)' can't be established.

ECDSA key fingerprint is SHA256:TJLbJ0EUJRSe7vzc1Y287Ymyo+jtZuVzRYUDHDuYCIk.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added '[gitlab.reposerver.com]:2222,[192.168.184.130]:2222' (ECDSA) to the list of known hosts.

PTY allocation request failed on channel 0

Welcome to GitLab, @centos!

Connection to gitlab.reposerver.com closed.

 Reference : in google, search  ssh config file sample

 [root@localhost devops1]#  vi /root/.ssh/config

 

[root@localhost devops1]# ssh git@gitlab.reposerver.com

no such identity: /root/.ssh/is_rsa: No such file or directory

git@gitlab.reposerver.com: Permission denied (publickey

 

[root@localhost devops1]# ssh git@gitlab.reposerver.com

PTY allocation request failed on channel 0

Welcome to GitLab, @centos!

Connection to gitlab.reposerver.com closed.

 

[root@localhost devops1]# chmod 600 /root/.ssh/id_rsa

[root@localhost devops1]# ssh git@gitlab.reposerver.com

PTY allocation request failed on channel 0

Welcome to GitLab, @centos!

Connection to gitlab.reposerver.com closed.

[root@localhost devops1]# cat /root/.ssh/config

Host gitlab.reposerver.com

    HostName gitlab.reposerver.com

     Port 2222

    IdentityFile /root/.ssh/id_rsa

IdentitiesOnly yes

 

 


 

 

 

 

No comments:

Post a Comment