gcloud使用ssh连接配置

1.进入实例面板 https://console.cloud.google.com/compute/instances

2.切换到root账户

sudo -i

  1. 修改SSH配置文件/etc/ssh/sshd_config

vi /etc/ssh/sshd_config

1
2
3
4
5
# Authentication:
PermitRootLogin yes //默认为no,需要开启root用户访问改为yes

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication yes //默认为no,改为yes开启密码登陆
  1. 给root账户设置密码

passwd root

  1. 重启SSH服务使修改生效
1
2
3
4
5
/etc/init.d/ssh restart

# 或者

systemctl restart sshd
  1. 添加本地的ssh公钥到gcloud元数据ssh中

方法二

  1. 切换到用户

su wx11055

  1. 生成ssh

ssh-keygen -f wx11055

  1. 拷贝wx11055.pub到本地
  2. 使用ssh工具导入pub连接
  3. 在.ssh文件夹下执行
1
ssh root@192.168.2.211  -i wx11055

通用免密登录方法

1
2
3
4
cat .ssh/id_rsa.pub | ssh root@192.168.1.32 'mkdir -p .ssh; cat >> .ssh/authorized_keys'

# 如果权限不够 请使用下面命令设置权限
ssh root@192.168.1.32 'chmod 700 .ssh; chmod 640 .ssh/authorized_keys'