The SSH (Secure SHell) protocol was designed with security and reliability in mind. Connections using SSH are secure: the partner is authenticated and all data exchanges are encrypted.
SSH 还涉及两个文件传输服务。 scp
是一个可以像cp
命令一样使用的命令行工具,除了指向其他机器的路径需要加机器名冒号前缀。
$
scp file machine:/tmp/
sftp
是一个交互命令,类似于 ftp
。在一个单独会话中, sftp
可以传输多个文件,并且可以远程操作文件(删除,重命名,更改许可,等等)。
Debian 使用 OpenSSH,一个由 OpenBSD
项目(注重安全,基于 BSD 内核的自由操作系统)维护的自由版本,它效仿了芬兰 SSH Communications Security Corp 公司开发的原始 SSH 软件。该公司最初将 SSH 作为自由软件开发,但是最终决定在专有许可下继续开发。然后,OpenBSD 项目创建了 OpenSSH 维护 SSH 的自由版本。
OpenSSH is split into two packages: the client part is in the openssh-client package, and the server is in the openssh-server package. The ssh meta-package depends on both parts and facilitates installation of both (apt-get install ssh
).
每次有人通过 SSH 登入,远程服务器询问密码来授权用户。如果想要自动连接或者使用需要频繁通过 SSH 连接的工具,这就会产生问题。这就是为什么 SSH 提供一种基于密钥的认证系统。
户在客户机上用 ssh-keygen -t rsa
产生密钥对;公共密钥存储在~/.ssh/id_rsa.pub
中,而对应的私有密钥存储在~/.ssh/id_rsa
中。然后,用户使用ssh-copy-id server
将他们的公共密钥添加到服务器上的 ~/.ssh/authorized_keys
文件中。如果私有密钥在创建的时候没有“口令密语”保护,随后所有在服务器上的登录将不需要口令。然而,私有密钥在每次输入口令时都必须被解密。幸运的是, ssh-agent
允许我们把私有密钥放在内存中而不必频繁重新输入口令。为此,可以简单的使用 ssh-add
(每个工作会话一次)来指明该会话已经和 ssh-agent
功能实例相关联。Debian 在图形界面会话中默认激活这一特性,也可以通过改变 /etc/X11/Xsession.options
来停用。对于控制台会话,可以使用 eval $(ssh-agent)
手动启动。
SSH 协议允许转发图形数据(“X11”会话,源于最广泛传播Unix图形系统的名字);然后,服务器为这些数据保留固定通道。特别地,远程执行的图形程序可以在本地系统X.org 服务器屏幕上显示,并且整个会话(输入和显示)都是安全的。由于该特性允许远程应用与本地系统交互,因此默认是关闭的。可以通过在服务配置文件(/etc/ssh/sshd_config
)中指明 X11Forwarding yes
来打开。最后,用户必须通过添加 -X
选项到 ssh
命令行中提出请求。
Its
-R
and
-L
options allow
ssh
to create “encrypted tunnels” between two machines, securely forwarding a local TCP port (see sidebar
BACK TO BASICS TCP/UDP) to a remote machine or vice versa.
运行
ssh -L 8000:server:25 intermediary
命令,将会建立同服务器主机
intermediary 的SSH 会话,并侦听本地端口8000 ¼参考see
图 9.2 “使用SSH转发本地端口”)。对于任何建立在该端口的连接,
ssh
将会发起从电脑
intermediary 到
server 端口25 的连接,并将两个连接绑定。
命令
ssh -R 8000:server:25 intermediary
也会建立电脑
intermediary 的SSH 会话,但是在本机
ssh
侦听端口8000 (参考
图 9.3 “使用SSH转发远程端口”)。在该端口建立的连接将
ssh
打开本机到
server25 端口的连接,并将两个连接绑定。
两种情况下,连接建立在server 主机的25 端口,它会透过SSH 隧道建立本地机器和中介机器的连接。在头一种情况下,到该隧道的入口是本地端口8000,数据在定向到公共网络的server 之前,流向 intermediary 。在第二种情况下,隧道输入输出被保留;入口是 intermediary 的8000 端口,输出在本地主机,然后数据被定向到 server。实际上,服务器不是本地机器就是中介机器。这样SSH 保护了一端到另一端的连接。
VNC (Virtual Network Computing)允许远程接入图形桌面
该工具主要用于技术支持;管理员可以看到用户面临的错误,并演示正确的操作而不必待在他们旁边。
First, the user must authorize sharing their session. The GNOME and KDE graphical desktop environments include, respectively, vino
and krfb
, which provide a graphical interface that allows sharing an existing session over VNC (both are identified as Desktop Sharing either in the GNOME application list or in the KDE menu). For other graphical desktop environments, the x11vnc
command (from the Debian package of the same name) serves the same purpose; you can make it available to the user with an explicit icon.
When the graphical session is made available by VNC, the administrator must connect to it with a VNC client. GNOME has vinagre
and remmina
for that, while KDE includes krdc
(in the menu at → → ). There are other VNC clients that use the command line, such as xvnc4viewer
in the Debian package of the same name. Once connected, the administrator can see what's going on, work on the machine remotely, and show the user how to proceed.
VNC also works for mobile users, or company executives, who occasionally need to login from their home to access a remote desktop similar to the one they use at work. The configuration of such a service is more complicated: you first install the vnc4server package, change the configuration of the display manager to accept XDMCP Query
requests (for gdm3
, this can be done by adding Enable=true
in the “xdmcp” section of /etc/gdm3/daemon.conf
), and finally, start the VNC server with inetd
so that a session is automatically started when a user tries to login. For example, you may add this line to /etc/inetd.conf
:
5950 stream tcp nowait nobody.tty /usr/bin/Xvnc Xvnc -inetd -query localhost -once -geometry 1024x768 -depth 16 securitytypes=none
将传入连接重定向到显示管理器解决了授权问题,只有拥有本地账户的用户才能通过 gdm
登录界面(或者 kdm
, xdm
,等)。由于这样允许多人同时登录而不会产生问题(前提是服务器足够强大),它甚至能给移动用户提供完整的桌面(或者配置为瘦客户机弱化的桌面系统),使用5950端口,用户只需简单的使用 vncviewer server:50
登入服务器即可。