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