SSH方式
# -C "your_email@example.com"
# -f bb
# -t rsa
# ~/.ssh/id_rsa.pub
# ~/.ssh/id_rsa
ssh-keygen -t rsa -b 4096 -N '' -m PEM
-m format
The supported key formats are: “RFC4716” (RFC 4716/SSH2 public or private key), “PKCS8” (PKCS8 public or private key) or “PEM” (PEM public key). By default OpenSSH will write newly-generated private keys in its own format, but when converting public keys for export the default format is “RFC4716”.
https://man7.org/linux/man-pages/man1/ssh-keygen.1.html-t dsa | ecdsa | ecdsa-sk | ed25519 | ed25519-sk | rsa Specifies the type of key to create. The possible values are “dsa”, “ecdsa”, “ecdsa-sk”, “ed25519”, “ed25519-sk”, or “rsa”. This flag may also be used to specify the desired signature type when signing certificates using an RSA CA key. The available RSA signature variants are “ssh-rsa” (SHA1 signatures, not recommended), “rsa-sha2-256”, and “rsa-sha2-512” (the default).
ssh-keygen -i -f ssh2.pub > openssh.pub
ssh-keygen -e -f openssh.pub > ssh2.pub
How to convert an SSH2 Public Key into an OpenSSH public key
Differences between “BEGIN RSA PRIVATE KEY” and “BEGIN OPENSSH PRIVATE KEY”
ProxyCommandhttp代理ssh(http over ssh)
## http 协议的代理
GIT_SSH_COMMAND='ssh -o ProxyCommand="nc -X connect -x 192.168.1.100:8118 %h %p"' git clone git@github.com:kubernetes/kubernetes.git
## SOCK5 协议的代理
GIT_SSH_COMMAND='ssh -o ProxyCommand="nc -X 5 -x 192.168.1.100:3000 %h %p"' git clone git@github.com:kubernetes/kubernetes.git
或者写入~/.ssh/config
文件
Host github.com
HostName github.com
User git
ProxyCommand nc -X connect 192.168.1.100:8118 %h %p
更改仓库地址
git config -l && \
git remote remove origin && \
git remote add origin git@github.com:dyrnq/dist.git && \
git config -l
强制回滚
git reset --hard 70fefa9854e587e1d7855a18978f463bcf84f18b && git push origin HEAD --force
第一次git clone ssh提示
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no)?
方式1
ssh-keygen -f "~/.ssh/known_hosts" -R github.com
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
方式2
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone user@host
方式3
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking accept-new" git clone user@host
参考https://stackoverflow.com/questions/7772190/passing-ssh-options-to-git-clone
其他
commit之后push之前想要撤回
git reset --soft HEAD^
git push
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
如果是以SSH方式连repo,确认本机id_rsa.pub拷贝到git server
git push
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/dyrnq/dist.git/'
https://github.com/settings/tokens创建Personal access tokens
git config
git config --local user.name "dyrnq" && git config --local user.emal "dyrnq@qq.com";
git config --global user.name "dyrnq" && git config --global user.email "dyrnq@qq.com"
git config --global core.editor "vim"
git config --global pull.ff only
git config --global http.proxy http://192.168.8.100:8118
git config --global https.proxy http://192.168.8.100:8118
git config --global --unset http.proxy
git config --global --unset https.proxy
git config --list --local
git config --list --global
create main branch
# 创建 git 仓库
mkdir example
cd example
git init
touch README.md
git add README.md
git commit -m "first commit"
git branch -M "main"
git remote add origin git@gitee.com:dyrnq/example.git
git push -u origin "main"