1. 程式人生 > >Google Cloud SSH 連線配置

Google Cloud SSH 連線配置

  1. 設定當前使用者及root使用者的密碼
sudo passwd xx-user
# 輸入新密碼
sudo passwd root
# 輸入新密碼(建議保持一樣)
  1. 在本地生成私鑰和公鑰
cd ~/.ssh
ssh-keygen -f myKey
。。。
# 此時會生成 公鑰 myKey.pub 和 私鑰 myKey
  1. 複製公鑰及匯入公鑰
  • 複製公鑰
cat myKey.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCjHKPaeglRVJzAhNq+W
中間部分省略。。。
dKx8sJ0Rw4kUqm2eU2vo8S5IEA0Nk2f7BtVGE8VOCHgmDbv2tLp9845UVp1 
[email protected]
# 全複製下來,把其中的 [email protected] 改為你在瀏覽器 SSH 登入之後的當前使用者名稱 xx-user
  • 匯入公鑰
# 進入谷歌雲平臺頁面 -> 計算引擎 -> 元資料 -> SSH 金鑰,貼上儲存即可
# 谷歌就會把上面這段 public key 寫入到 ~/.ssh/authorized_keys
  1. 新增密碼驗證登陸
sudo vi /etc/ssh/sshd_config
# 找到PasswordAuthentication 並修改為
PasswordAuthentication yes 
# wq!儲存退出

# 修改完重啟 ssh 服務
$ sudo service sshd restart
  1. 給當前使用者xx-user新增許可權

如果不新增在之後的ssh登陸後,要進入root時,會報xx-user is not in the sudoers file. This incident will be reported.

操作如下:sudo vi /etc/sudoers
,找到root ALL=(ALL) ALL這一行
在起下面新增xx-user ALL=(ALL) ALL(這裡的xx-user是你的使用者名稱),新增完後wq!儲存退出

  1. 通過 SSH 密碼驗證登入
ssh [email protected]
# 輸入密碼後即可登陸
  1. 通過私鑰登入
ssh -i myKey [email protected]