Mac配置ssh连接github账户相关步骤

Mac ssh Configuration for Connecting Github

When you buy a new Macbook Pro or a new Mac-mini, your ssh configuration will be invalid to your github account before. So you need to make a new config.

Generate ssh keys

To communicate with your own Github account by ssh(Secure Shell), first you need to do is to generate a ssh key, including private key and public key.

Done by commands below:

ssh-keygen -t rsa -C "Your-Github-Email" -f "~/.ssh/id_rsa_Your-Github-Username"

Then the prompt hints you to set a passphrase, which makes your ssh key more secure. You can input any sequences of words, characters, or other text used to control access to your SSH key.

After that, you can gain your own ssh keys in the “~/.ssh” directory, which contains id_rsa_Your-Github-Username and id_rsa_Your-Github-Username.pub file. And the former is your own private key, while the later is the public key.

Add the SSH key to the SSH agent

Start the SSH agent in the background:

eval "$(ssh-agent -s)"

Add the ssh key:

ssh-add "~/.ssh/id_rsa_Your-Github-Username"

Add the SSH key to your Github Account

  • Copy the ssh key(public key)
pbcopy < "~/.ssh/id_rsa_Your-Github-Username.pub"
  • Go to GitHub -> Settings -> SSH and GPG keys -> New SSH key, and paste the key.

Config Git Details for your repo

After you clone a repo from your own Github account and made some changes in your local workspace, you need to configure your git username and email to this local repo.

git clone "https://github.com/Git-Username/Git-reponame.git"
git config user.name "Your-Github-Username"
git config user.email "Your-Github-Email"

In my opinon, till now, you can use your local mac computer to manage your github repo. But if you have more than one Github accounts, you need still to make some configurations to seperate different accounts with different ssh keys.

Configure SSH to use different keys for different Github accounts

  • Create the ssh config file
touch "~/.ssh/config"
  • Edit the config file, and add the configuration content to it
vim "~/.ssh/config"
# Account1
Host github-account1
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_account1

# Account2
Host github-account2
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_account2
  • 12
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SSH连接GitHub步骤如下: 1. 首先,确认你还没有设置SSH。打开终端,输入cd ~./ssh(默认目录)或者其它你设置过的ssh目录位置并回车。如果终端返回No such file or directory,那说明你应该新设置一个SSH。 2. 生成SSH密钥。在终端输入ssh-keygen -t rsa并回车。按两次回车,第一次选择SSH密钥的存储位置,默认位置是/home/\[用户名\]/.ssh/id_rsa;第二次回车时选择passphrase,可以选择留空或者设置一个密码。 3. 确认生成SSH密钥。在终端内重新输入步骤1的指令cd ~/.ssh和ls,确认SSH密钥文件已被生成。 4. 复制SSH密钥。在终端输入cat id_rsa.pub获取SSH公共密钥内容,复制ssh-rsa ... @mail.ericfrenzy.fun。 5. 在GitHub上添加SSH密钥。在设置页面找到SSH and GPG keys,点击New SSH key。在Title处填写一个你能认出的名字,将刚才复制的SSH公共密钥粘贴到下方的文字框内,点击Add SSH key。 6. 测试连接。在终端输入ssh -T git@github.com并回车。输入yes确认连接。如果出现Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.,说明SSH密钥配置成功。 请注意,在使用git clone等命令时,要使用SSH的URL而不是HTTPS的。 以上是连接GitHubSSH步骤。\[2\] #### 引用[.reference_title] - *1* [使用 ssh 连接 Github 代码库超详细教程](https://blog.csdn.net/snsHL9db69ccu1aIKl9r/article/details/101803787)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [在本地配置SSH连接GitHub以及其它服务器(详细图文教程)](https://blog.csdn.net/EricFrenzy/article/details/126904024)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值