Chinaunix首页 | 论坛 | 博客
  • 博客访问: 178163
  • 博文数量: 59
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2015-06-29 10:38
个人简介

我以为我们可以一起走到最后,呵呵。。。 结果才走了两步,你说你要打的

文章分类
文章存档

2015年(59)

我的朋友

分类: 系统运维

2015-07-23 11:45:07

传统的网络服务程序,如:ftp、pop和telnet在本质上都是不安全的,因为它们在网络上用传送口令和数据,的人非常容易就可以截获这些口令和数据。而且,这些服务程序的安全验证方式也是有其弱点的, 就是很容易受到“”(man-in-the-middle)这种方式的攻击。所谓“中间人”的攻击方式, 就是“中间人”冒充真正的服务器接收你的传给服务器的数据,然后再冒充你把数据传给真正的服务器。 服务器和你之间的数据传送被“中间人”一转手做了手脚之后,就会出现很严重的问题。

   SSH的英文全称是Secure Shell。通过使用SSH,你可以把所有传输的数据进行加密,这样“中间人”这种攻击方式就不可能实现了, 而且也能够防止DNS和IP欺骗。还有一个额外的好处就是传输的数据是经过压缩的,所以可以加快传输的速度。 SSH有很多功能,它既可以代替telnet,又可以为ftp、pop、甚至ppp提供一个安全的“通道”。


第一种级别(基于口令的安全验证)只要你知道自己帐号和口令,就可以登录到远程主机。所有传输的数据都会被加密, 但是不能保证你正在连接的服务器就是你想连接的服务器。可能会有别的服务器在冒充真正的服务器, 也就是受到“中间人”这种方式的攻击。

   第二种级别(基于的安全验证)需要依靠密匙,也就是你必须为自己创建一对密匙,并把公用密匙放在需要访问的服务器上。 如果你要连接到SSH服务器上,客户端软件就会向服务器发出请求,请求用你的密匙进行安全验证。服务器收到请求之后, 先在该服务器的家目录下寻找你的公用密匙,然后把它和你发送过来的公用密匙进行比较。如果两个密匙一致, 服务器就用公用密匙加密“质询”(challenge)并把它发送给客户端软件。 客户端软件收到“质询”之后就可以用你的私人密匙解密再把它发送给服务器。

用这种方式,你必须知道自己密匙的口令。但是,与第一种级别相比,第二种级别不需要在网络上传送口令。

第二种级别不仅加密所有传送的数据,而且“中间人”这种攻击方式也是不可能的(因为他没有你的私人密匙)。 但是整个登录的过程可能需要10秒。  
 以下操作就是采用第二种方式,但秘钥的生成是在服务器上。

环境:linux-rhel6.4
客户主机:server36
服务器:server47


1.生成密钥

[root@server47 .ssh]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): (指定保存密钥的文件,选择默认即可)
Enter passphrase (empty for no passphrase): xxxxx(输入密码,应大于5位
Enter same passphrase again:xxxxx(再次输入密码)
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:
a4:ce:10:3a:e4:b2:14:46:dd:31:5c:52:6c:ef:f7:b5 root@server47.example.com
The key's randomart image is:
+--[ RSA 2048]----+
| .. o+=o         |
|.  . ooo         |
| o. . . o        |
|.o.. . o .       |
|..+ . . S        |
|.o . +   . .   . |
|.     o   . . . .|
|             . E |
|                 |
+-----------------+
[root@server47 .ssh]# ls
id_rsa  id_rsa.pub  known_hosts
其中:id_rsa是私钥,即钥匙,id_rsa.pub是公钥即锁头

2.用锁头对192.168.74.147主机的root用户加密:
[root@server47 .ssh]# ssh-copy-id -i id_rsa.pub root@192.168.74.147
The authenticity of host '192.168.74.147 (192.168.74.147)' can't be established.
RSA key fingerprint is c0:bc:87:97:a2:06:fb:e1:fa:78:4b:93:6c:81:71:72.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.74.147' (RSA) to the list of known hosts.
root@192.168.74.147's password: 
Now try logging into the machine, with "ssh 'root@192.168.74.147'", and check in:
  .ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.

[root@server47 .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
#出现authorized_keys文件表示已加密,若文件authorized_keys被删,执行“cp id_rsa.pub authorized_keys”命令即可 

3.共享私钥
方法一,用scp远程拷贝:
[root@server47 .ssh]# scp id_rsa 192.168.74.136:/root/.ssh/
root@192.168.74.136's password: 
id_rsa                                        100% 1743     1.7KB/s   00:00  
方法二,使用网络共享:
[root@server47 .ssh]# cp id_rsa /var/www/html/
[root@server47 html]# chmod 644 id_rsa 

4.下载密钥:
[root@server36 .ssh]# wget
--2014-12-29 05:13:04--  
Connecting to 192.168.74.147:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1743 (1.7K) [text/plain]
Saving to: “id_rsa”
100%[======================================>] 1,743       --.-K/s   in 0s      
2014-12-29 05:13:04 (127 MB/s) - “id_rsa” saved [1743/1743]

5. 更改权限:
[root@server36 .ssh]# chmod 600 id_rsa 

6.ssh连接解密:
[root@server36 .ssh]# ssh 192.168.74.147
Enter passphrase for key '/root/.ssh/id_rsa': 
Last login: Thu Aug  7 23:40:30 2014  #解密成功
注:1.因用命令wget网络下载id_rsa文件,故需执行命令chmod 644 id_rsa,使id_rsa文件有可执行权限
      2.chmod 600 id_rsa命令作用:避免权限过大,若未使用此命令,则会出现如下错误:
[root@server36 .ssh]# ssh 192.168.74.147
The authenticity of host '192.168.74.147 (192.168.74.147)' can't be established.
RSA key fingerprint is c0:bc:87:97:a2:06:fb:e1:fa:78:4b:93:6c:81:71:72.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.74.147' (RSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/root/.ssh/id_rsa' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /root/.ssh/id_rsa
root@192.168.74.147's password: 




阅读(1260) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~