1. 程式人生 > 其它 >VScode 免密登入

VScode 免密登入

1.在本地電腦配置公私鑰
# 輸入 
ssh-keygen -t rsa
 
# 防止忘記,建議一路回車 
# 預設 金鑰id_rsa和公鑰id_rsa.pub檔案都預設儲存在(C:\User\使用者/.ssh)資料夾下)
2.將公鑰拷貝到遠端伺服器使用者目錄下
# 方法1用scp檔案傳輸
scp id_rsa.pub root@192.168.255.130:/root/.ssh/
 
# 方法2用xftp 6工具將公鑰id_rsa.pub直接複製到/root/.ssh/目錄下
 
# 將公鑰內容寫入檔案中 
cat id_rsa.pub >> authorized_keys 
 
# 許可權 
chmod 600
authorized_keys # 遠端server的配置即修改好了
3.在vscode中配置host user
# 即windows C:\Users\xxx\.ssh\config檔案
# 或者vscode的設定按鈕可以直接配置
Host xxx # 遠端連線名字
  HostName xxx # ip
  User xxx # 登入使用者名稱
4.當有多個伺服器開發時,可以同樣配置免密登入。只需完成上述2,3步驟即可。
# 1.scp 已配置的主機下的authorized_keys 到需要配置免密的主機 
scp authorized_keys root@ip:
/root/.ssh/ # 2.免密主機許可權設定 chmod 600 authorized_keys # 3.vscode設定settings,編輯config檔案