Google 云主機(jī)連接教程

來源:簡書
作者:皇家豆瓣醬
時間:2020-06-21
2662
如何創(chuàng)建賬號創(chuàng)建實(shí)例這里就不說了,網(wǎng)上一大堆教程,而且基本上會有引導(dǎo),指引一步步完成,這里只說創(chuàng)建好實(shí)例之后,如何連接到服務(wù)器

如何創(chuàng)建賬號創(chuàng)建實(shí)例這里就不說了,網(wǎng)上一大堆教程,而且基本上會有引導(dǎo),指引一步步完成,這里只說創(chuàng)建好實(shí)例之后,如何連接到服務(wù)器

在谷歌云后臺打開ssh連接控制臺

compute Engine ---> 虛擬機(jī)實(shí)例 就會看到自己創(chuàng)建的實(shí)例

1969751-9af07d9ae5766559.jpg

設(shè)置root密碼

1.設(shè)置下 root 的新密碼

$ sudo passwd root

# 輸入新密碼

1969751-02a5bf3eb3d446fa.jpg

在本地生成私鑰和公鑰

$ cd ~/.ssh

$ ssh-keygen -f myKey

Generating public/private rsa key pair.

Enter passphrase (empty for no passphrase): (給 private key 設(shè)置一個密碼,避免私鑰被人盜用的風(fēng)險)

Enter same passphrase again: (再次輸入上次相同密碼)

Your identification has been saved in myKey.

Your public key has been saved in myKey.pub.

The key fingerprint is:

SHA256:EW7ow1wCKAh1rM/GG08ZAwOy+7+SUiT0rFXY2f8mNvk user@computer-name.local

The key's randomart image is:

+---[RSA 2048]----+

|=.o+= o .        |

|o+.o+= + .       |

|o.o..oo *        |

|..o+ +o+ o       |

|.oo+  =+S o      |

| o. * o. = o     |

| ..o =  . =      |

|. o.. .    E     |

| . .o.           |

+----[SHA256]-----+

# 此時會生成 公鑰 myKey.pub 和 私鑰 myKey

復(fù)制公鑰

$ cat myKey.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCjHKPaeglRVJzAhNq+W

中間部分省略。。。

dKx8sJ0Rw4kUqm2eU2vo8S5IEA0Nk2f7BtVGE8VOCHgmDbv2tLp9845UVp1 user@computer-name.local

把這長長的一段復(fù)制下來,把其中的 user@computer-name.local 改為你在瀏覽器 SSH 登入之后的當(dāng)前用戶名 ${whoami}

導(dǎo)入公鑰

進(jìn)入谷歌云平臺頁面 -> 計算引擎 -> 元數(shù)據(jù) -> SSH 密鑰,粘貼保存

谷歌就會把上面這段 public key 寫入到 ~/.ssh/authorized_keys

這里我沒有進(jìn)行復(fù)制粘貼這一步,打開之后默認(rèn)就已經(jīng)存在在這里了,忘了是哪里添加過了

1.jpg

本地通過私鑰登錄

$ ssh -i myKey root@34.***.***.***          // 替換為自己的ip地址

Enter passphrase for key 'myKey': (輸入 private key 密碼)

Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.11.2-041102-generic x86_64)


 * Documentation:  https://help.ubuntu.com

 * Management:     https://landscape.canonical.com

 * Support:        https://ubuntu.com/advantage


  Get cloud support with Ubuntu Advantage Cloud Guest:

    https://www.ubuntu.com/business/services/cloud


83 packages can be updated.

0 updates are security updates.


Last login: Sun Oct  8 06:40:43 2017 from 115.200.175.117

通過 SSH 密碼驗(yàn)證登錄

$ ssh root@34.***.***.***

Permission denied (publickey).

之后會出現(xiàn)訪問被拒絕

之所以會出現(xiàn)這種情況,因?yàn)楣雀枘J(rèn)把密碼驗(yàn)證登錄關(guān)了,需要自行打開

修改 SSH 登錄配置

$ sudo vi /etc/ssh/sshd_config

PermitRootLogin yes           //默認(rèn)為no,需要開啟root用戶訪問改為yes

PasswordAuthentication yes    //默認(rèn)為no,改為yes開啟密碼登陸

修改完按ESC 然后按shift + : 輸入 wq 回車保存退出

改完要重啟 ssh 服務(wù)

$ reboot

再次連接

$ ssh root@34.***.***.***

root@34.***.***.***'s password: (輸入實(shí)例用戶的密碼)

Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.11.2-041102-generic x86_64)

 * Documentation:  https://help.ubuntu.com

 * Management:     https://landscape.canonical.com

 * Support:        https://ubuntu.com/advantage


  Get cloud support with Ubuntu Advantage Cloud Guest:

    https://www.ubuntu.com/business/services/cloud


83 packages can be updated.

0 updates are security updates.


Last login: Sun Oct  8 06:59:24 2017 from 115.200.175.117

至此大功告成

立即登錄,閱讀全文
原文鏈接:點(diǎn)擊前往 >
版權(quán)說明:本文內(nèi)容來自于簡書,本站不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。文章內(nèi)容系作者個人觀點(diǎn),不代表快出海對觀點(diǎn)贊同或支持。如有侵權(quán),請聯(lián)系管理員(zzx@kchuhai.com)刪除!
優(yōu)質(zhì)服務(wù)商推薦
更多
掃碼登錄
打開掃一掃, 關(guān)注公眾號后即可登錄/注冊
加載中
二維碼已失效 請重試
刷新
賬號登錄/注冊
個人VIP
小程序
快出海小程序
公眾號
快出海公眾號
商務(wù)合作
商務(wù)合作
投稿采訪
投稿采訪
出海管家
出海管家