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]
# 全复制下来,把其中的 user@machin-1 改为你在浏览器 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]

猜你喜欢

转载自www.cnblogs.com/cjr0707/p/10024057.html