前面已经讲过ssh的安装和免密码登陆,这里ssh可以写一个简单的脚本方便执行
#!/bin/sh ssh hostname@ip接下来讲下github的使用
- 安装Git, 使用命令sudo apt-get install git
- 创建GitHub帐号
- 生成ssh key,使用命令 ssh-keygen -t rsa -C "[email protected]",your_email是你的email
- 回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,粘贴key。
- 测试ssh key是否成功,使用命令ssh -T [email protected],如果出现You’ve successfully authenticated, but GitHub does not provide shell access ,这就表示已成功连上github。
- 配置Git的配置文件:配置用户名:git config --global user.name "your name" ,配置email:git config --global user.email "your email"
首先要检查key是不是已经存在,打开一个终端,并输入以下命令:
$ ls -al ~/.ssh
如果结果列表中包含以下文件, 则不需要在生成新的KEY, 可以直接使用。
id_dsa.pub、id_ecdsa.pub、id_ed25519.pub、id_rsa.pub
如果不存在, 则需要创建新的Key来使用。
输入下面的命令来生成key, 注意替换你自己的邮箱地址。
$ ssh-keygen -t rsa -C "your_email"
# Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home_path/.ssh/id_rsa):
这里在提示你保存key的位置, 默认直接回车就可以。
当以上步骤成功完成后, 你将看到类似与这样的结果:
Your identification has been saved in /your_home_path/.ssh/id_rsa.
Your public key has been saved in /your_home_path/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
执行以下命令将KEY加入到ssh-agent:
$ eval "$(ssh-agent -s)"
# Agent pid 59566
$ ssh-add ~/.ssh/id_rsa
打开 ~/.ssh/id_rsa.pub文件, 复制其中所有的内容。然后把它粘贴到github的ssh key添加的表单中。
执行以下命令来测试key。
$ ssh -T [email protected]
如果你看到:
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
输入“yes”并回车。
当你看到以下内容时, 你就添加成功了。
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.
1 利用Git从本地上传到GitHub
第一步: 进入要所要上传文件的目录输入命令 “git init”
第二步: 创建一个本地仓库origin,使用命令 “git remote add origin [email protected]:yourName/yourRepo.git”
youname是你的GitHub的用户名,yourRepo是你要上传到GitHub的仓库
第三步: 比如你要添加一个文件xxx到本地仓库,使用命令 “git add xxx”,可以使用“git add .”自动判断添加哪些文件
然后把这个添加提交到本地的仓库,使用命令 ”git commit -m ”说明这次的提交“ “
最后把本地仓库origin提交到远程的GitHub仓库,使用命令 ”git push origin master“
2 从GitHub克隆项目到本地
第一步: 到GitHub的某个仓库,然后复制右边的有个“HTTPS clone url”
第二步: 回到要存放的目录下,使用命令 "git clone https://github.com/chenguolin/scrapy.git",红色的url只是一个例子
第三步: 如果本地的版本不是最新的,可以使用命令 “git fetch origin”,origin是本地仓库
第四步: 把更新的内容合并到本地分支,可以使用命令 “git merge origin/master”
如果你不想手动去合并,那么你可以使用: git pull <本地仓库> master // 这个命令可以拉去最新版本并自动合并