日期:2014-05-16  浏览次数:20891 次

ssh在linux安全中的作用

安全 Shell (SSH)是最通用的系统管理工具之一。它允许登录远程系统并在其上执行命令。

它利用强大的加密技术和主机密钥来防止网络嗅探。他是默认启用的唯一网络服务,并且接

受远程访问。

X 选项 可使远程主机上的程序在本地桌面环境下显示图形界面。这带来了便利,而且为本

地主机与远程主机之间的通信通道提供了保护

 

[root@localhost ~]# ssh 192.168.1.1

The authenticity of host '192.168.1.1 (192.168.1.1)'can't be established.

RSA key fingerprint is83:8f:76:3a:42:31:b0:95:49:72:8a:a7:1c:39:08:e6.

Are you sure you want to continue connecting (yes/no)?yes

Warning: Permanently added '192.168.1.1' (RSA) to thelist of known hosts.

root@192.168.1.1's password:

Last login: Sun Aug 28 22:05:29 2011

[root@station1 ~]#

  

[root@localhost ~]# ssh user1@192.168.1.1

user1@192.168.1.1's password:

Last login: Fri Jun 17 01:11:57 2011 from 192.168.1.254

[user1@station1 ~]$

 

******************************************************************************

安全 Shell (SSH)允许使用私钥-公钥进行身份验证。私钥自己妥善保管,公钥告知任何人。

拥有公钥的 SSH 服务器可以发布仅由私钥的系统才可解答的问题。因此可以根据所

持有的密钥进行验证。这样在每次访问系统时不必键入密码,但安全性仍能得到保证。

 

可以使用ssh-keygen 命令生成密钥

[root@localhost ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enterfile in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase): 123456

Enter same passphrase again: 123456

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

0c:cf:fc:b0:e3:00:5a:dd:6d:7b:1d:af:9c:8b:05:86root@localhost.localdomain

 

在生成密钥期间,将提供用与指定密码的选项。必须提供密码才能访问私钥。通过此方法,

即使密钥被盗,也很难使用密钥。这样在攻击者破解并使用私钥前,可以生成新的密钥

并删除所有涉及旧密钥的内容。

 

生成 SSH 密钥后,密钥将默认存储在家目录的 .ssh/ 目录中

[root@localhost ~]# ls ~/.ssh/

id_rsa id_rsa.pub  known_hosts


可以使用ssh-copy-id 将自己的公钥复制到目标系统

[root@localhost ~]# ssh-copy-id -i ~/.ssh/id_rsa.pubuser1@192.168.1.1

user1@192.168.1.1's password:

Now try logging into the machine, with "ssh'user1@192.168.1.1'", and check in:

.ssh/authorized_key

[root@localhost ~]# ssh user1@192.168.1.1

Last login: Tue Sep 6 10:50:26 2011 from 192.168.1.254

[user1@station1 ~]$

 

SSH 端口转发

==============================================================================

SSH 会自动加密和解密所有 SSH 客户端与服务端之间的网络数据。但是,SSH 还同时提供

了一个非常有用的功能,这就是端口转发。它能够将其他 TCP 端口的网络数据通过 SSH 链

接来转发,并且自动提供了相应的加密及解密服务。这一过程有时也被叫做“隧道”

(tunneling),这是因为 SSH 为其他 TCP 链接提供了一个安全的通道来进行传输而得名。

例如,Telnet,SMTP,LDAP 这些 TCP 应用均能够从中得益,避免了用户名,密码以及隐私

信息的明文传输。而与此同时,如果您工作环境中的防火墙限制了一些网络端口的使用,但

是允许 SSH 的连接,那么也是能够通过将 TCP 端口转发来使用 SSH 进行通讯。总的来说

SSH 端口转发能够提供两大功能:

加密 SSHClient 端至 SSHServer 端之间的通讯数据。

突破防火墙的限制完成一些之前无法建立的 TCP 连接。


Client<------------>SSHServer<-------------->WEB Server

  

SSH Server:1.1.1.254/24&