git SSH keys

An SSH key allows you to establish a secure connection between your computer and GitLab. Before generating an SSH key in your shell, check if your system already has one by running the following command:

Windows Command Line:

type %userprofile%\.ssh\id_rsa.pub

GNU/Linux/Mac/PowerShell:

cat ~/.ssh/id_rsa.pub

If you see a long string starting with ssh-rsa, you can skip the ssh-keygen step.

Note: It is a best practice to use a password for an SSH key, but it is not required and you can skip creating a password by pressing enter. Note that the password you choose here can‘t be altered or retrieved.

To generate a new SSH key, use the following command:

ssh-keygen -t rsa -C "[email protected]"

This command will prompt you for a location and filename to store the key pair and for a password. When prompted for the location and filename, just press enter to use the default. If you use a different name, the key will not be used automatically.

Use the command below to show your public key:

Windows Command Line:

type %userprofile%\.ssh\id_rsa.pub

GNU/Linux/Mac/PowerShell:

cat ~/.ssh/id_rsa.pub

Copy-paste the key to the ‘My SSH Keys‘ section under the ‘SSH‘ tab in your user profile. Please copy the complete key starting with ssh-rsa and ending with your username and host.

To copy your public key to the clipboard, use the code below. Depending on your OS you‘ll need to use a different command:

Windows Command Line:

type %userprofile%\.ssh\id_rsa.pub | clip

Windows PowerShell:

cat ~/.ssh/id_rsa.pub | clip

Mac:

pbcopy < ~/.ssh/id_rsa.pub

GNU/Linux (requires xclip):

xclip -sel clip < ~/.ssh/id_rsa.pub

Deploy keys

Deploy keys allow read-only access to multiple projects with a single SSH key.

This is really useful for cloning repositories to your Continuous Integration (CI) server. By using deploy keys, you don‘t have to setup a dummy user account.

If you are a project master or owner, you can add a deploy key in the project settings under the section ‘Deploy Keys‘. Press the ‘New Deploy Key‘ button and upload a public SSH key. After this, the machine that uses the corresponding private key has read-only access to the project.

You can‘t add the same deploy key twice with the ‘New Deploy Key‘ option. If you want to add the same key to another project, please enable it in the list that says ‘Deploy keys from projects available to you‘. All the deploy keys of all the projects you have access to are available. This project access can happen through being a direct member of the project, or through a group. See def accessible_deploy_keys in app/models/user.rb for more information.

Deploy keys can be shared between projects, you just need to add them to each project.

Applications

Eclipse

How to add your ssh key to Eclipse: https://wiki.eclipse.org/EGit/User_Guide#Eclipse_SSH_Configuration

Tip: Non-default OpenSSH key file names or locations

If, for whatever reason, you decide to specify a non-default location and filename for your GitLab SSH key pair, you must configure your SSH client to find your GitLab SSH private key for connections to your GitLab server (perhaps gitlab.com). For OpenSSH clients, this is handled in the ~/.ssh/config file with a stanza similar to the following:

#
# Main gitlab.com server
#
Host gitlab.com
RSAAuthentication yes
IdentityFile ~/my-ssh-key-directory/my-gitlab-private-key-filename
User mygitlabusername

Another example

#
# Our company‘s internal GitLab server
#
Host my-gitlab.company.com
RSAAuthentication yes
IdentityFile ~/my-ssh-key-directory/company-com-private-key-filename

Note in the gitlab.com example above a username was specified to override the default chosen by OpenSSH (your local username). This is only required if your local and remote usernames differ.

Due to the wide variety of SSH clients and their very large number of configuration options, further explanation of these topics is beyond the scope of this document.

Public SSH keys need to be unique, as they will bind to your account. Your SSH key is the only identifier you‘ll have when pushing code via SSH. That‘s why it needs to uniquely map to a single user.

时间: 2024-12-19 22:25:55

git SSH keys的相关文章

Git 进阶指南(git ssh keys / reset / rebase / alias / submodule )

在掌握了基础的 Git 使用 之后,可能会遇到一些常见的问题.以下是猫哥筛选总结的部分常见问题,分享给各位朋友,掌握了这些问题的中的要点之后,git 进阶也就完成了,它包含以下部分: 如何修改 origin 仓库信息 如何配置 git ssh keys 如何撤销修改 遇到冲突了怎么解决 git stash / alias / submodule 的使用问题等 问:如何修改 origin 仓库信息? 1.添加 origin 仓库信息 git remote add origin <git仓库地址>

git ssh keys生成步骤

1.在github上面注册... 2.生成ssh密钥生成过程 1).查看是否已经有了ssh密钥: cd ~/.ssh 2).生成密钥 $ ssh-keygen -t rsa -C "[email protected]"  (注册github的邮箱账号) 回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key.为了验证是否成功,在git bash下输入: $ ssh -T [email protected]

git: windows git ssh keys生成

http://blog.csdn.net/lsyz0021/article/details/52064829 当我们使用github或者bitbucket等仓库时我们有可能需要ssh认证,所以需要生成他的ssh key. 1.首先你要安装Git工具 下载地址:https://git-scm.com/downloads 2.右键鼠标,选中 "Git Bash here",当然你也可以在windows的 "开始"--->"所以程序",或者安装目

Ubuntu下升级Git以及获取ssh keys的代码

今天开始用的git,记下获取ssh keys 的代码 ? 1 2 3 ssh-keygen -t rsa -C "[email protected]" # Enter file in which to save the key (/home/you/.ssh/id_rsa): ssh-add id_rsa http://my.oschina.net/silentboy/blog/195741?p=1 这里建议直接回车,就在当前目录下创建id_rsa.pub,不然会像我一样,路径搞错,v

创建SSH keys用于添加到Git服务器上

SSH keys SSH key 可以让你在你的电脑和Git服务器之间建立安全的加密连接.先执行以下语句来判断是否已经存在本地公钥: cat ~/.ssh/id_rsa.pub 如果你看到一长串以 ssh-rsa或 ssh-dsa开头的字符串, 你可以跳过 ssh-keygen的步骤. 提示: 最好的情况是一个密码对应一个ssh key,但是那不是必须的.你完全可以跳过创建密码这个步骤.请记住设置的密码并不能被修改或获取. 你可以按如下命令来生成ssh key: ssh-keygen -t rs

Generating SSH keys

Generating SSH keys MAC WINDOWS LINUX ALL SSH keys are a way to identify trusted computers, without involving passwords. The steps below will walk you through generating an SSH key and adding the public key to your GitHub account. We recommend that y

为github帐号添加SSH keys(Linux和Windows)

文章转自:https://blog.cofface.com/archives/406.html/2 一.Linux增加ssh keys方法: 使用git clone命令从github上同步github上的代码库时,如果使用SSH链接(如我自己的cofface_recovery项目:[email protected]:cofface/cofface_recovery.git),而你的SSH key没有添加到github帐号设置中,系统会报下面的错误:Permission denied (publi

mac下生成ssh keys 并上传github仓储

使用github仓储需要本机生成一个公钥key 添加到自己的git账户SSH keys中 mac 生成方法: 1. 打开终端 输入 ssh-keygen 然后系统提示输入文件保存位置等信息,连续敲三次回车即可,生成的SSH key文件保存在中-/.ssh/id_rsa.pub 2. 然后用文本编辑工具打开该文件,我用的是vim,所以命令是: vim ~/.ssh/id_rsa.pub 将内容拷贝到github里起个名字就可以了. 注意:拷贝.pub中的内容时候需要将"ssh-rsa"这

git ssh 绑定 GitLab

入职新公司之后,需要使用GitLab,可是我不会啊,又不想麻烦运维大佬,所以自己找乐一下,发现网上都是些很陈旧的教程,所以准备自己记录下来 第一步 设置Git端上的用户名和用户邮箱: 假如入你已经安装了Git 右键Git Bash Here 第二步生成ssh公钥和私钥 然后一路回车 之后,你会看到这个,里面包含了你的公钥私钥所在的路径,当然你也可以在产生之初,修改它的存放位置,我使用的是默认 C/Users/admin/.ssh 这个路径 然后我们找到文件 第三步 在GitLab里面添加公钥(i