Gitlab Configure SSH Connection

Source: Internet
Author: User
Tags aliases
SSH Public Key login

Typically, when administering a remote host, SSH is logged in, SSH user@host, but the password is used every time. The key pair that is generated by using Ssh-keygen, and then the public key is added to the target host's ~/.ssh/authorized_keys file, the current host becomes a trusted host, and the next time you log in with SSH, you don't have to enter the password.

Gitlab,github support this way of connection, the following steps: Step one : Generate key Pair

To generate a key pair using Ssh-keygen:

Ssh-keygen-t rsa-c "your mailbox."

This generates two files Id_rsa and id_rsa.pub in the. SSH directory in the home directory. The private key is saved in the ID_RSA and the public key is saved in the id_rsa.pub. Step Two: Add the public key

Copy public key to clipboard:

Pbcopy < Id_rsa.pub

When you paste the public key in the profile->ssh keys->add new page, you add it. Step three: Test

SSH Plus-t option tests whether the target service is available:

Ssh-t git@ "Your Gitlab server address."

The first time you connect, you are asked to trust the host, and then enter Yes when you confirm. If you see Welcome to Gitlab, rusher! even if the configuration is successful, then you can submit the code via SSH.

Windows Downloads Git-bash generates a key pair ssh-keygen-t rsa-c "Your mailbox" is generated and then opens the file in Notepad c:/user/administrator/.ssh/id_rsa.pub, and then The Gitlab that adds the public key. Test ssh-t git@ "Your Gitlab server address" Gitlab service-side configuration

(Use client only to ignore this section)

The following error was found while submitting the client:

/usr/local/lib/ruby/1.9.1/net/http.rb:762:in ' Initialize ': getaddrinfo:name or service not known (SOCKETERROR) from/ Usr/local/lib/ruby/1.9.1/net/http.rb:762:in ' Open ' from/usr/local/lib/ruby/1.9.1/net/http.rb:762:in ' block in Connect ' from/usr/local/lib/ruby/1.9.1/timeout.rb:54:in ' timeout ' from/usr/local/lib/ruby/1.9.1/timeout.rb:99:in ' Timeout ' from/usr/local/lib/ruby/1.9.1/net/http.rb:762:in ' Connect ' from/usr/local/lib/ruby/1.9.1/net/http.rb:755 : In ' Do_start ' from/usr/local/lib/ruby/1.9.1/net/http.rb:744:in ' Start ' from/home/git/gitlab-shell/lib/gitlab_ Net.rb:64:in ' Get ' from/home/git/gitlab-shell/lib/gitlab_net.rb:30:in ' check ' from./check:11:in ' <main> '

In GitHub issue find said first run a/home/git/gitlab-shell/bin/check. Do the test first and find the same error as above. See the error is unable to find the domain name, so in the/etc/hosts need to configure a map of the address.

127.0.0.1 Your_domin # Your_domin is configured in/home/git/gitlab-shell/config.yml Gitlab_url extension: SSH multi-User Switching

In the configuration of Gitlab when the first is to use the Administrator account to do the test, and then built my own account to do development. So I have two local Gitlab account, if the direct use of SSH to submit the code is problematic, because SSH defaults to use a start to generate id_rsa that key pair, but different accounts can not correspond to the same public key. If multiple accounts are used together, you will need to make some configuration.

If there are two accounts: root and rusher. Step one: Generate key pairs for two separate accounts

Tip Where to store the key file, the different account fill different paths, root placed under the/users/you/.ssh/id_rsa_gitlab_root, rusher placed in the/users/you/.ssh/id_rsa_gitlab_ Rusher

Ssh-keygen-t rsa-c rusher@you.com generating public/private RSA key pair. Enter file in which to save the key (/USERS/YOU/.SSH/ID_RSA):/users/you/.ssh/id_rsa_gitlab_rusher Enter passphrase (empty For no passphrase: Enter same passphrase Again:your identification has been saved Er. Your public key has been saved in/users/you/.ssh/id_rsa_gitlab_rusher.pub. Ssh-keygen-t rsa-c root@you.com generating public/private RSA key pair. Enter file in which to save the key (/USERS/YOU/.SSH/ID_RSA):/users/you/.ssh/id_rsa_gitlab_root Enter passphrase (empty F or no passphrase): Enter same passphrase Again:your identification has been saved. Your public key has been saved in/users/you/.ssh/id_rsa_gitlab_root.pub.

The SSH keys (rusher:id_rsa_gitlab_rusher.pub and Root:id_rsa_gitlab_root.pub) of the respective accounts that need to be added to the two account's public key separately.

Ssh-add/users/you/.ssh/id_rsa_gitlab_rusher Ssh-add/users/you/.ssh/id_rsa_gitlab_root Step Two: Add SSH configuration file

Add a config file to the. SSH directory that adds aliases to the different accounts (Root:root_gitlab and Rusher:rusher_gitlab), connects to the same server, but uses a different key file to separate the two accounts.

# for Root host Root_gitlab HostName git.you.com User git identityfile/users/you/.ssh/id_rsa_gitlab # for rusher Host Rus Her_gitlab HostName git.you.com User git identityfile/users/you/.ssh/id_rsa_gitlab_rusher

After the configuration is complete, use the Ssh-add command

Then use the alias test to see if it corresponds to the correct account:

Ssh-t Git@root_gitlab ssh-t Git@rusher_gitlab Step Three: Use aliases in Git projects

Normal project, after we clone down, origin corresponding URL assumes: Git@git.:rusher/helloworld, now need to make a change, will git. To replace Rusher_gitlab,

git remote Set-url origin Git@rusher_gitlab:rusher/helloworld

If this is the root user's project:

git remote Set-url origin Git@root_gitlab:root/helloworld

The above method of configuring SSH also applies to websites such as Github,bitbucket. reference Documentation Github Help

UPDATE 2013-08-16: After generating a key pair for a different account, you need to use Ssh-add to add the key, or SSH will not use the correct key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.