github
ssh
linux
This page is edited from Auther: 辛西 (Cynthia)【Git】使用 SSH 金鑰與 GitHub 連線
mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Enter file in which to save the key (/home/kuihao-ubuntu/.ssh/id_rsa):
github_rsa_key
Enter passphrase (empty for no passphrase):
password
Enter same passphrase again:
password
The key fingerprint is:
SHA256: <sha-token> your_email@example.com
The key's randomart image is:
±–[RSA 4096]––+
| … … … |
| … … … |
| … … … |
| … … … |
| … … … |
| … … … |
| … … … |
| … … … |
| … … … |
±–-[SHA256]––-+
cd ~/.ssh && ls
github_rsa_key github_rsa_key.pub
cat ~/.ssh/github_rsa_key.pub
ssh-rsa ABC…89xyz== your_email@example.com
If you want to copy with command line: xclip
Settings
SSH and GPG keys
New SSH keys
MyLabDesktopUbuntu2004
ssh-rsa ABC…89xyz== your_email@example.com
ssh -T git@github.com
ECDSA key fingerprint is SHA256:************
Are you sure you want to continue connecting (yes/no/[fingerprint])?
yes
then:
Warning: Permanently added 'github.com,52.69.186.44' (ECDSA) to the list of known hosts.
Hi XXX! You've successfully authenticated, but GitHub does not provide shell access.
git remote -v
origin https://github.com/YourGithubUserName/YourGithubRepo.git (fetch)
origin https://github.com/YourGithubUserName/YourGithubRepo.git (push)
git remote set-url origin git@github.com:YourGithubUserName/YourGithubRepo.git
git remote -v
origin git@github.com:YourGithubUserName/YourGithubRepo.git (fetch)
origin git@github.com:YourGithubUserName/YourGithubRepo.git (push)
NOTICE!!
This article continues Cynthia's blog under the CC BY-NC-SA 4.0 license. Please cite author, link and source for republication!
scp ~/.ssh/<your_local_key_name>.pub <remote-user>@140.116.xxx.yyy:~/.ssh/<xyz_key>.pub
以下命令要在遠端主機:
cat ~/.ssh/<xyz_key>.pub >> ~/.ssh/authorized_keys
sudo chmod 400 ~/.ssh/authorized_keys
sudo service ssh restart
finished