ssh-keygen -t rsa -C "your_email@example.com" Generating public/private rsa key pair. Enter file inwhich to save the key (/Users/your_user_directory/.ssh/id_rsa):[按回车键] #如果需要创建多个ssh key并且已存在ssh key,需要起别名再按回车键(例如:id_rsa.work),否则会覆盖原来的ssh key Enter passphrase (empty for no passphrase):[输入密码] Enter same passphrase agin:[再次输入密码]
Your identification has been saved in /Users/your_user_directory/.ssh/id_rsa. Your public key has been saved in /Users/your_user_directory/.ssh/id_rsa.pub The key fingerprint is: [fingerprint值] your_email@example.com The key's randomart image is: [略]
ssh -T git@github.com The authenticity of host 'github.com(192.30.252.120)' can't be established. RSA key fingerprint is [fingerpring值]. Are you sure you want to continue connecting(yes/no)?[输入yes]
出现如下结果即为成功。
1
Hi your_username! You've successfully authenticated,but GitHub does not provide shell access.
如何使用GitHub(二)
创建仓库
实际创建一个公开的仓库。点击右上角工具栏中的“+”下拉菜单里的New repository,创建新的仓库。 在Repository name 栏中输入仓库的名称。
Description栏中可以设置仓库的说明。这一栏不是必须项,可以留空。
选择Public,创建公开仓库,仓库内的所有内容都会被公开。
选择Private,创建非公开仓库,用户可以设置访问权限,但这项服务是收费的。
在Initialize this repository with a README选项上打钩,随后GitHub会自动初始化仓库并设置README文件,让用户可以立刻clone这个仓库。如果想向GitHub添加手中已有的Git仓库,建议不要勾选,直接手动push。
下方右侧的下拉菜单Add a license可以选择要添加的许可协议文件。如果这个仓库中包含的代码已经确定了许可协议,那么请在这里进行选择。随后将自动生成包含许可协议内容的LICENSE文件,用来表明仓库内容的许可协议。
输入选择都完成后,点击Create repository按钮,完成仓库的创建。
clone已有仓库
1 2
git clone 仓库的路径 cd 目录名称
编写代码
1
vim test.php
1 2 3
<?php echo"Hello World"; ?>
查看状态
1
git status
提交
1 2
git add test.php git commit -m "Add test.php"
通过git add命令将文件加入暂存区,再通过git commit命令提交。
添加成功后,可以通过git log命令查看提交日志。
1
git log
进行push
之后只要执行push,GitHub上的仓库就会被更新。
1
git push
这样一来代码就在GitHub上公开了。
常见问题
Warning: Permanently added ‘github.com,192.30.252.120’ (RSA) to the list of know
1 2 3 4 5 6
ssh -T git@github.com The authenticity of host 'github.com (192.30.252.120)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,192.30.252.120' (RSA) to the list of known hosts. Permission denied (publickey).
解决方案:
1 2 3 4
cd .ssh ls -la rm -rf id_rsa rm -rf id_rsa.pub
重新设置SSH Key,并添加公开密钥。
Warning: Permanently added the RSA host key for IP address ‘192.30.252.129’ to t
Warning: Permanently added the RSA host key for IP address ‘192.30.252.129’ to the list of known hosts. 解决方案: