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 user@computer-name.local
# 全复制下来,把其中的 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 xx-user@1.1.1.1
# 输入密码后即可登陆
  1. 通过私钥登录
ssh -i myKey xx-user@1.1.1.1

转载于:https://www.cnblogs.com/cjr0707/p/10024057.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值