介绍
你最终拥有VPS(虚拟私人服务器),但你可能仍然在想,并说:`我将如何连接到我的Sev,因为我没有cpanel来输入我的用户名和密码?``让我向你保证,Debian(我们将在本教程中使用什么)或任何其他Linux发行版,你可以实现和做任何cpanel或任何Web面板可以做的事情。
因此,请不要被命令行吓坏,一开始看起来很困难,但一旦你在DigitalOcean上阅读了几个优秀的教程,你就会自己看到它有多么容易。
第一次连接到你的VPS
你的VPS可能离你几千英里远,但是,通过几个程序,你可以连接到它,就像它在你面前一样,最重要的是,所有这些程序允许你通过所谓的 **'SSH'**安全连接到你的服务器。
SSH是什么?
SSH (Secure Shell) 是用于服务器和客户端(You)之间进行安全数据通信的网络协议(例如:命令行登录和身份验证,远程命令执行,甚至是数据传输)。
Figure 1: Basic concepts of SSH protocol
OpenSSH 和 PuTTY
因此,OpenSSH 和 PuTTY 是其他几个SSH 程序中仅有的两种。 OpenSSH是 Debian 提供的最流行的和最广泛使用的SSH 程序。 PuTTY是 Windows OS 中最受欢迎的SSH 程序。
在 Windows 中安装和配置 PuTTY
由于OpenSSH已经安装在我们的服务器上,您只需要安装PuTTY才能连接到您的服务器。 请访问PuTTY的官方下载页面从 <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html"target="_blank">这里下载安装文件,它看起来像 [putty-x.xx-installer.exe]。 下载后,安装它,就像你会安装任何Windows程序一样;只需确保仅为当前用户安装它,特别是如果您的PC被许多用户使用。 安装完成后,启动PuTTY,并将出现配置窗口(图2)。
Figure 2: PuTTY configuration window
Now, just follow the following steps in order to connect to your server for the first time:
**1.** In the **Host Name (or IP address)** field, enter your droplet IP address, which you can get from either:
- 您在创建滴滴后收到的电子邮件(图 3)
- 您的数字海洋控制面板(图 4)
Figure 3: Email sample of newly created droplet
Figure 4: DigitalOcean control panel
**2.** Just make sure that the **Port** field shows number **22**; since it's the default port number for SSH protocol, and also the **Connection type** set to SSH as in (Figure 2).
**3.** In the **Saved Sessions** field, write a name for your session and then hit SAVE; this will save all the configurations we did earlier; so that the next time you launch PuTTY, you wouldn't have to enter your server's configuration and your PuTTY preferences all over again.
**4.** Finally you are ready to connect to your server, either by selecting the session name and then clicking the **Open** button at the bottom or simply double-clicking the session name that you have saved earlier.
服务器客户端身份验证
二、服务器身份验证

Figure 5: PuTTY Security Alert
After initiating the connection to your server as we discussed earlier, you'll notice that the configuration window disappeared and instead a black terminal window has appeared but with a **'Security Alert'** (Figure 5). Don't freak out, this alert is expected to appear **ONLY** the first time you connect to a server that you've never connected to before. To make it simple for you to understand why this scary alert window appeared, I'm going to use a simple analogy: say you drove a fancy car to a 5-star hotel, then a valet asks for your car's key in order to park it. The question is: Do you trust this guy who is asking for your fancy car's keys? The answer to this question will determine your final decision. Your answer is going to be based (subconsciously) at least on:
- 男孩的衣服.
- 他佩戴的徽章和/或酒店的标志或他的制服上的名字。
当你的客户端的SSH程序(PuTTY)第一次连接到你的服务器的SSH程序(OpenSSH)时,也会发生同样的事情。现在,作为一个客户端,你有一个非常敏感的信息,即你的登录凭证,即你的Debian服务器的帐户用户名和密码。
Figure 6: The 2-steps of Server-Client authentication
上面的图6简要地解释了分离身份验证和两个端之间建立安全连接期间发生的背景操作:
1. PuTTY 联系 OpenSSH.
2. OpenSSH 通过发送一个 主机密钥和一些其他参数来识别自己与 PuTTY。
3. PuTTY 反过来,通过其已知的主机数据库 查找 OpenSSH 在步骤 2 发送的 主机密钥是否退出。
因此,Putty 的主机密钥基本上是车主的制服和徽章。 它只是为您的服务器的 SSH 程序(OpenSSH)提供了一个独特的指纹,这有助于 PuTTY 在未来的会话中识别它。
- 再次返回窗口中的 **
安全警报
(图5),假设您正确输入了服务器的 IP 地址,现在可以安全地点击是
。
5. 最后,服务器身份验证完成并建立安全连接。
二、客户端身份验证
既然你终于安全地连接到你的 sever,现在通过SSH加密连接发送你的登录凭证是安全的(图6)。你可以从你收到的电子邮件中获得你的主要登录凭证,一旦滴滴被创建(图3)。下面的图像显示了一个终端命令行,你将输入你的 用户名在行中说登录为:
,然后点击 Enter
,然后出现一个新的行要求你的 password,输入它并点击 Enter
。
**在输入密码时,你会注意到命令行中的方针不会移动或显示任何星座. 不要担心 - 即使在输入命令行时似乎没有任何东西出现在命令行上,你在键盘上按下的每一个键实际上都被输入并发送到你的服务器。
Figure 7: The beginning of client authentication process
You will know that the client authentication process was successful when the terminal shows you what appears in (Figure 7). This is basically brief information about the Linux distribution that is installed on your server, information about the last time you logged in, and the last line is where all the magic happens and it's called the **'Command or Prompt line'**, and its structure is similar to the following:
username@hostname:~#
第一个部分表示您当前登录的用户名,然后是主机名称,由@
符号分开,随后是当前目录(在本示例中~
指的是当前用户主目录),哈希符号表示命令行的尽头。
注意!注意!!
对于每个Linux发行版,命令行可能略有不同,但基本上它们都具有相同的结构。
结论
学习是一个缓慢而渐进的过程,我希望你已经掌握了远程连接到服务器背后的基本概念,以及为什么安全性在不断拥挤的不安全的互联网世界中如此重要,以及SSH如何帮助你保持这一点。