常用命令速查
常用组合(可选)
新增/修改后提交流程:
git statusgit add .git commit -m "feat: ..."git push
同步远程最新:
git pull解决冲突(如有)
git push(如需要推送本地提交)
Git 基础配置 + SSH Key 配置(GitHub 与免密登录)
本文整理 Git 基础配置 + SSH Key 配置(GitHub 与免密登录)。按顺序执行即可。
配置用户信息
git config --global user.name "username"
git config --global user.email "youremail@email.com"可选:查看当前配置
git config --global --list生成 SSH Key(id_rsa / id_rsa.pub)
ssh-keygen -t rsa密钥默认存放目录:
~/.ssh/
.ssh/
├── authorized_keys
├── id_rsa
├── id_rsa.pub
└── known_hosts
authorized_keys: 免密登录/密钥登录(服务器端)
id_rsa: 私钥(不要泄露)
id_rsa.pub: 公钥(可公开)
known_hosts: 记录已登录过的机器信息配置 GitHub SSH Key
在 GitHub 设置里打开
SSH and GPG keys点击
New SSH key填写
Title(任意名称)Key type默认即可将
id_rsa.pub的内容复制到Key输入框
提示:查看公钥内容
cat ~/.ssh/id_rsa.pub测试 GitHub 连通性
ssh -T git@github.com配置服务器免密登录(authorized_keys)
将本机公钥复制到服务器
scp -P 22 ~/.ssh/id_rsa.pub root@ipAddr:~/id_rsa.pub在服务器上追加到
authorized_keys(推荐用追加,避免覆盖)
mkdir -p ~/.ssh
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys测试登录
ssh root@ipAddr