Windows免密登录Linux + 配置多个Github账号
就當【碎碎】平安了,忘掉不愉快,今天分享兩個超簡單、超實用的Window實用技能。
三步完成windows免密登錄linux
1)在windows上生成秘鑰:
啟動Git, ssh-keygen -t rsa -C "xxx@163.com", 生成秘鑰:id_rsa.pub, id_rsa
默認生成在C盤:
C:\Users\DELL\.ssh 的目錄2022/04/07 09:43
.2022/04/07 09:43 ..2022/04/07 09:43 54 config2019/04/27 07:21 1,831 id_rsa2019/04/27 07:21 401 id_rsa.pub2022/06/11 15:02 2,138 known_hosts 4 個文件 4,424 字節(jié) 2 個目錄 19,970,998,272 可用字節(jié)
2)上傳秘鑰到linux服務器:
復制公鑰 id_rsa.pub 的全部內(nèi)容到服務 .ssh/authorized_keys當中,保存authorized_keys。
3) 啟動 ssh server:
啟動命令:service sshd restart, 然后windows 退出linux服務器登錄后重新登錄即可完成免密登錄了。
2.一臺Windows電腦,配置多個Github賬號、實現(xiàn)代碼上傳
一臺Windows電腦,怎么配置多個Github賬號,實現(xiàn)代碼上傳呢?我們分享在 windows10上同時創(chuàng)建 paperClub-hub 和 user2items 兩個Github賬號, 其實整個過程只用三步。
1)生成秘鑰
打開Git, 檢查C盤根目錄下有沒有 .ssh文件夾,如果沒有自己創(chuàng)建一下就可以了。我們先生成兩個秘鑰 is_rsa_paperClub-hub 和 is_rsa_user2items:
ssh-keygen -t rsa -f is_rsa_paperClub-hub
ssh-keygen -t rsa -f is_rsa_user2items
直接回車,其他不用管,這樣就生成了秘鑰,is_rsa_paperClub-hub 和 is_rsa_user2items是為了舉例子,大家可以根據(jù)自己的需要創(chuàng)建 。
DELL@DESKTOP-IDPMAV4 MINGW64 ~/.ssh$ lsconfig id_rsa.pub id_rsa_paperClub-hub.pub id_rsa_user2items.pubid_rsa id_rsa_paperClub-hub id_rsa_user2items known_hosts
2)上傳公鑰到Github
這一步比較簡單:打開登錄github 賬號(以paperClub-hub為例) , 點擊github右上角的頭像-->settings --> SSH and GPG keys 中,然后再點擊“new SSH key”,
設置SSH keys Title, 然后編輯器打開剛才生成的 id_rsa_paperClub-hub.pub 文件,復制全部內(nèi)容到 SSH keys Key: 下的空白框內(nèi)(github賬號和公鑰對應,別混了),然后點擊 “add SSH Key”就完成了Github秘鑰的配置。
驗證:
$ssh -T git@user2items.github.com
Hi user2items! You've successfully authenticated, but GitHub does not provide shell access.
$ssh -T git@paperClub-hub.github.com
Hi paperClub-hub! You've successfully authenticated, but GitHub does not provide shell access.
以上說明配置完成。
3)本地配置及驗證
在C盤創(chuàng)建一個config文件(如果沒有的話),內(nèi)容:
Host paperClub-hub.github.com
HostName github.com
User paperClub-hub
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_paperClub-hub
Host user2items.github.com
HostName github.com
PreferredAuthentications publickey
User user2items
IdentityFile ~/.ssh/id_rsa_user2items
配置其實目的就是為了方便管理,當然也可以不做。我們這樣做就是盡可能的和github上的url保持一致,比如 Host 和 HostName。> 郵箱及用戶配置,這個先重置全局信息,然后分布進行配置,比較簡單。>然后用Git進入本地的git的文件夾。創(chuàng)建 本地倉儲: git init> 關聯(lián)遠端:
https:
$ git remote add origin https://github.com/user2items/paperClub.git
ssh:
$ git remote add origin git@github.com: user2items/paperClub.git
上面的 github.com為 config中的 HostName, 后面緊接著是用戶名和遠端的倉儲位置,我們仔細看一下,其實就是githup上 https的 URL : https://github.com/user2items/paperClub.git> 拉去遠端代碼:
$ git pull origin master
From https://github.com/user2items/paperClub
- branch master -> FETCH_HEAD
- [new branch] master -> origin/master
Already up to date.
> 上傳代碼:
$ git push origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 353 bytes | 353.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote:
remote: GitHub found 32 vulnerabilities on user2items/paperClub's default branch (1 critical, 14 high, 15 moderate, 2 low). To find out more, visit:
remote: https://github.com/user2items/paperClub/security/dependabot
remote:
To https://github.com/user2items/paperClub.git
a7abd55..d86c781 master -> master
`
怎么樣,是不是很簡單呢?
總結
以上是生活随笔為你收集整理的Windows免密登录Linux + 配置多个Github账号的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 从0开始教你玩个人网盘NAS,跟手机电脑
- 下一篇: 快手“子弹时间”技术首次应用于国际级击剑