谷歌云设置SSH访问

一、登录谷歌云GCP后台

首先我们要登录GCP的后台,然后选择相应的虚拟机实例。

二、设置root密码

1.先选择从浏览器打开ssh连接服务器

2.切换到root账号,输入如下命令

<span class="pln">sudo </span><span class="pun">-</span><span class="pln">i</span>

3.设置root密码

<span class="pln">passwd</span>

然后会要求输入新密码,然后再重复一次密码

输入密码的时候不会显示出来,所以直接输入密码,然后回车,再然后重复输入密码回车

谷歌云GCP设置默认SSH开启ROOT权限图文教程3

三、开启SSH权限

方法一

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

<span class="pln">vi </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">ssh</span><span class="pun">/</span><span class="pln">sshd_config</span>

2.然后再输”i”进入编辑模式

<span class="pln">i</span>

3.找到以下内容并修改

<span class="typ">PermitRootLogin</span><span class="pln"> yes           </span><span class="com">//默认为no,需要开启root用户访问改为yes</span>
<span class="typ">PasswordAuthentication</span><span class="pln"> yes    </span><span class="com">//默认为no,改为yes开启密码登陆</span>
谷歌云GCP设置默认SSH开启ROOT权限图文教程4

4.修改完成后,再下按 esc 键,然后再输入

<span class="pun">:</span><span class="pln">wq</span>
谷歌云GCP设置默认SSH开启ROOT权限图文教程5

5.重启服务器

<span class="pln">reboot</span>

方法二

CentOS和Debian通用,输入以下两条命令,分别回车

<span class="pln">sed </span><span class="pun">-</span><span class="pln">i </span><span class="str">'s/PermitRootLogin no/PermitRootLogin yes/g'</span> <span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">ssh</span><span class="pun">/</span><span class="pln">sshd_config</span>
<span class="pln">sed </span><span class="pun">-</span><span class="pln">i </span><span class="str">'s/PasswordAuthentication no/PasswordAuthentication yes/g'</span> <span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">ssh</span><span class="pun">/</span><span class="pln">sshd_config</span>

Ubuntu系统,输入以下两条命令,分别回车

<span class="pln">sed </span><span class="pun">-</span><span class="pln">i </span><span class="str">'s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g'</span> <span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">ssh</span><span class="pun">/</span><span class="pln">sshd_config</span>
<span class="pln">sed </span><span class="pun">-</span><span class="pln">i </span><span class="str">'s/PasswordAuthentication no/PasswordAuthentication yes/g'</span> <span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">ssh</span><span class="pun">/</span><span class="pln">sshd_config</span>

重启谷歌云GCP服务器

<span class="pln">reboot</span>

接下来我们就可以用SSH工具登录了。一般默认的地址是分配的IP地址,然后端口号是22,登录后,用户名自然就是root,然后密码是前面设置好的。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享