github ssh key添加方法和简单git 命令收藏

For MAC Users:

To create an SSH Key, go to your terminal (or iTerm 2) and enter ssh-keygen. You will be prompted for a file in which to save the key (.ssh/id_rsa). There’s no need to enter anything, just press enter. When prompted for a passphrase, you can enter one or just press enter to ignore creating a passphrase.

Your SSH key has been saved to ssh/id_rsa.pub, run the command pbcopy < ~/.ssh/id_rsa.pub to copy this to your clipboard.

Now go to your Github account setting for Key: https://github.com/settings/keys and click ‘New SSH key’. Add any title you want, like ‘First SSH Key’, paste in your SSH key, and click the ‘Add SSH key’ button.

For PC Users:

To create an SSH Key, go to your terminal and enter ssh-keygen. You will be prompted for a file in which to save the key (.ssh/id_rsa). There’s no need to enter anything, just press enter. When prompted for a passphrase, you can enter one or just press enter to ignore creating a passphrase.

Your SSH key has been saved to ssh/id_rsa.pub, run the command cat ~/.ssh/id_rsa.pub to see your SSH key in the proper format. Copy the whole text string starting with ‘ssh’ to the end.

Now go to your Github account setting for keys: https://github.com/settings/keys and click ‘New SSH key’. Add any title you want, like ‘First SSH Key’. Paste your SSH key to the Key window, and click the ‘Add SSH key’ button.

There are a lot of complex functionalities of Git, but for 99% of work there are 4 things that you need to be able to do:

  1. Create a branch git checkout -b my-branch-name

  2. Add files that you want to queue up for saving.

    • To add all files: git add .

    • To add a specific file: git add path-to-file

  3. Save (commit) changes to the files that you added above. git commit -m "message about this commit. Ex: change button color to green."

  4. Sync your branch to Github so that you can later make a pull request. git push -u origin my-branch-name

更多精彩文章:
https://datasciencebyexample.com/
datascience tribe

### 配置GitHub上的SSH密钥 #### 创建新的SSH密钥 为了简化向GitHub推送项目的流程并提高安全性,可以创建一个新的SSH密钥。如果已经在CentOS客户端机器上有现有的SSH密钥对,则可能会被新生成的密钥覆盖[^4]。 对于Linux或Mac用户,在终端执行如下命令来生成SSH密钥: ```bash ssh-keygen -t rsa -b 4096 -C "your_email@example.com" ``` 此命令会提示指定保存位置,默认情况下可以直接按回车键接受默认路径;接着设置密码保护私钥文件的安全性(可选),再次确认输入相同的密码完成操作。 #### 添加SSH密钥至SSH代理程序 启动SSH代理服务并将刚产生的公钥加入其中以便后续使用: ```bash eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa ``` 这里假设`id_rsa`是你刚才创建的身份验证密钥名称,如果不是这个名,请替换为你自己的密钥名字。 #### 将SSH密钥添加GitHub账户 复制刚刚生成的公共部分的内容,通常位于`~/.ssh/`目录下的`id_rsa.pub`文件内。可以通过以下方式快速获取其内容: ```bash cat ~/.ssh/id_rsa.pub ``` 登录到GitHub网站后进入个人资料页面中的“SSH and GPG keys”,点击右上角的新建按钮上传之前复制好的公钥文本框里粘贴进去,并给它起个有意义的名字方便识别管理,最后提交保存即可[^1]。 #### 测试连接有效性 通过下面这条指令测试是否成功建立了与GitHub服务器之间的信任关系: ```bash ssh -T git@github.com ``` 正常情况下应该收到一条欢迎消息表示一切顺利!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值