添加用户

1
2
3
adduser aliyun #新建用户
usermod -aG sudo aliyun #绑定到sudo组 即赋予sudo权限

SSH 相关

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
ssh user@hostname -p port # 登录服务器 并指定端口
~/.ssh/config #配置文件
Host myserver1
HostName IP地址或域名
User 用户名

Host myserver2
HostName IP地址或域名
User 用户名

ssh-keygen # 生成ssh秘钥
id_rsa :私钥
id_rsa.pub :公钥

ssh-copy-id myserver #配置免密登录

#利用远程服务器直接运行代码
ssh myserver 'for ((i = 0; i < 10; i ++ )) do echo $i; done'

#将本地文件上传服务器

#将本地家目录中的 tmp 文件夹复制到 myserver 服务器中的 /home/acs/ 目录下
scp -r ~/tmp myserver:/home/acs/
将本地家目录中的 tmp 文件夹复制到 myserver 服务器中的 ~/acs 目录下。
scp -r ~/tmp myserver:acs

#将服务器文件下载到本地
# 将 myserver 服务器中的 ~/homework/ 文件夹复制到本地的当前路径下。
scp -r myserver:homework .

git

git 注册信息

1
2
3
git config --global user.name xxx : 设置全局用户名,信息记录在 ~/.gitconfig 文件中

git config --global user.email xxx@xxx.com : 设置全局邮箱地址,信息记录在 ~/.gitconfig 文件中

git 单分支基本指令

1
2
3
4
5
6
7
8
9
10
11
12
13
git init : 将当前目录配置成 git 仓库,信息记录在隐藏的 .git 文件夹中

git add XX : 将 XX 文件添加到 暂存区

git add . : 将所有待加入 暂存区 的文件加入 暂存区 (. 可以用 * 代替)

git rm --cached XX : 将文件从 仓库索引目录 中 删掉

git commit -m "给自己看的备注信息" : 将 暂存区 的内容 提交 到 当前分支

git status : 查看仓库 状态

git diff XX : 查看 XX 文件相对于 暂存区 修改了哪些内容

git 单分支版本切换指令

1
2
3
4
5
6
7
8
9
10
11
12
13
git log : 查看当前分支的 所有版本

git reflog : 查看 HEAD指针 的 移动历史(包括被回滚的版本,这是回滚后再回来的方法)

git reset --hard HEAD^ 或 git reset --hard HEAD~ : 将代码库 回滚 到 上一个版本

git reset --hard HEAD^^ : 往上 回滚 两次,以此类推(几个 ^ 就回滚几次)

git reset --hard HEAD~100 : 往上 回滚 100个版本,以此类推(~n 回滚 n 次)

git reset --hard 版本号 : 回滚 到某一特定版本

git checkout — XX 或 git restore XX : 将 XX 文件 尚未加入暂存区 的修改 全部撤销

git 单分支与远程仓库交互的指令

1
2
3
4
5
6
7
git remote add origin git@git.acwing.com:xxx/XXX.git : 将本地仓库关联到远程仓库

git push -u (第一次需要-u以后不需要) : 将当前分支推送到远程仓库

git push origin branch_name : 将本地的 某个分支 推送到远程仓库

git clone git@git.acwing.com:xxx/XXX.git : 将远程仓库 XXX 下载 到当前目录下

git 多分支管理指令

1
2
3
4
5
6
7
8
9
git branch : 查看 所有分支 和 当前所处分支

git branch branch_name : 创建 新分支

git checkout -b branch_name : 创建并切换 到 branch_name 这个分支

git checkout branch_name : 切换 到 branch_name 这个分支

git merge branch_name : 将分支 branch_name 合并 到 当前分支 上

git 多分支与远程仓库交互的指令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
git branch -d branch_name : 删除 本地仓库 的 branch_name 分支

git push -d origin branch_name : 删除 远程仓库 的 branch_name 分支

git push --set-upstream origin branch_name : 设置 本地仓库 的 branch_name 分支与 远程仓库 的 branch_name 分支 对应

git branch --set-upstream-to=origin/branch_name1 branch_name2 : 将 远程仓库 的 branch_name1 分支与 本地仓库 的 branch_name2 分支 对应

git pull : 将 远程仓库 的 当前分支 与 本地仓库 的 当前分支 合并

git pull origin branch_name : 将 远程仓库 的 branch_name 分支与 本地仓库 的当前分支 合并

git checkout -t origin/branch_name : 将 远程仓库 的 branch_name 分支拉取到 本地仓库

git stash暂存
git stash : 将 工作区 和 暂存区 中 尚未提交 的修改存入 栈 中

git stash apply : 将 栈顶 存储的修改 恢复 到 当前分支 ,但 不删除 栈顶元素

git stash drop : 删除 栈顶 存储的修改

git stash pop : 将 栈顶 存储的修改 恢复 到当前分支,同时删除 栈顶元素

git stash list : 查看 栈中 所有元素