Mac 下 配置使用 github

本文详细介绍了如何生成新的SSH密钥对,并将其用于GitHub账户的身份验证。包括了创建密钥、备份旧密钥、配置GitHub以及测试连接等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

$ ls -la
total 8
drwx------   3 wide288  staff  102 12  2 12:06 .
drwxr-xr-x@ 18 wide288  staff  612  3  2 08:14 ..
-rw-r--r--   1 wide288  staff  396 12  2 12:06 known_hosts


做原有key的备份,不过用处不大。
mkdir key_backup
$ ls
key_backup known_hosts


创建新的key
$ ssh-keygen -t rsa -C "wide288@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/wide288/.ssh/id_rsa): github_key // github_key 是我输入的文件名
Enter passphrase (empty for no passphrase): // 输入密码
Enter same passphrase again: 
Your identification has been saved in github_key.
Your public key has been saved in github_key.pub.
The key fingerprint is:
71:fc:9f:2b:8a:bf:d2:a8:0e:71:63:7b:3d:8f:d6:79 wide288@163.com
The key's randomart image is:



查看结果
$ ls -la
total 24
drwx------   6 wide288  staff   204  3 11 11:41 .
drwxr-xr-x@ 18 wide288  staff   612  3  2 08:14 ..
-rw-------   1 wide288  staff  1766  3 11 11:41 github_key
-rw-r--r--   1 wide288  staff   397  3 11 11:41 github_key.pub
drwxr-xr-x   2 wide288  staff    68  3 11 11:39 key_backup

-rw-r--r--   1 wide288  staff   396 12  2 12:06 known_hosts


登录 github.com

右上角 account settings ---> SSH keys ---> add SSH Keys

保存下 github_key.pub 的内容


$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.252.129)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:de:a9:98.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts.
Permission denied (publickey).

如保解决,把 github 二个文件 改为 id_rsa

Identity added: /Users/wide288/.ssh/id_rsa (/Users/renqi/.ssh/id_rsa)

Hi wide288! You've successfully authenticated, but GitHub does not provide shell access.

成了


git config --global user.name "wide288"

git config --global user.email "wide288@***.com"


account settings ---> applications ---> generate a new token

git config --global github.user wide288

git config --global github.token 44ee07c60937aaaaaaaa164315e




### 如何在 Mac使用 GitHub 进行代码管理与协作 #### 安装 Git 工具 为了能够在 Mac使用 GitHub,首先需要安装 Git。可以通过 Homebrew 或者直接下载官方版本来完成安装。如果已经安装了 Xcode Command Line Tools,则可能已预装 Git[^1]。 验证是否安装成功可以运行以下命令: ```bash git --version ``` 如果没有安装或者需要更新至最新版,可通过以下方式安装: ```bash brew install git ``` #### 配置 SSH 密钥 为了让本地计算机能够安全地访问远程仓库而无需每次都输入用户名和密码,建议配置 SSH 密钥。按照提示操作完成后,测试连接是否正常: ```bash ssh -T git@github.com ``` 当返回类似于 `Hi Cloudox! You've successfully authenticated` 的消息时,说明设置成功[^2]。 #### 创建或克隆仓库 对于新项目,可以在 GitHub 网站上新建一个仓库,并通过如下命令将其初始化为 Git 仓库并推送到远端服务器: ```bash echo "# myproject" >> README.md git init git add README.md git commit -m "first commit" git branch -M main git remote add origin https://github.com/username/myproject.git git push -u origin main ``` 如果是参与现有项目,通常会 fork 到个人账户下再进行 pull request 流程。具体步骤包括 Fork 原始库、Clone 自己的副本到本地机器以及定期同步上游更改等[^3]: ```bash git clone https://github.com/your-username/repo-name.git cd repo-name touch test.txt git add . git commit -am 'Add new file' git push origin main ``` #### 使用图形界面工具 (可选) 除了命令行外,还有多种 GUI 应用程序可供选择,如 GitHub Desktop, Sourcetree 等,它们简化了很多日常任务的操作流程[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值