返回首页
当前位置: 主页 > 办公软件 > WPS教程 >

三步实现免密码SSH

时间:2016-04-06 14:11来源:电脑教程学习网 www.etwiki.cn 编辑:admin

SSH 为 Secure Shell 的缩写,是目前较可靠,专为远程登录会话和其他网络服务提供建立在应用层和传输层基础上的安全性协议。

从客户端看,SSH提供两种安全验证。一为基于账户和口令的方式,可能会有别的服务器在冒充真正的服务器,也就是受到“中间人”这种方式的攻击。第二种为基于秘钥的安全验证。此方式需要先预先创建一对秘钥,再将此公钥发送到被控制端,之后就可以一劳永逸的在客户端和服务器之间建立了安全连接,而且也避免了中间人攻击的可能。

下面我将分三个步骤演示创建并分发公钥到服务器

一、创建一对密钥

使用ssh-keygen -t dsa 命令创建一对密钥

 

ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/home/cnchanghai/.ssh/id_dsa):

/home/cnchanghai/.ssh/id_dsa already exists.

Overwrite (y/n)?

~ ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/home/cnchanghai/.ssh/id_dsa):

/home/cnchanghai/.ssh/id_dsa already exists.

Overwrite (y/n)? y

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/cnchanghai/.ssh/id_dsa.

Your public key has been saved in /home/cnchanghai/.ssh/id_dsa.pub.

The key fingerprint is:

e6:c0:6c:65:9b:c4:3b:79:d1:3b:9f:dd:bb:88:6c:c1 cnchanghai@ch-notepc

The key's randomart image is:

+--[ DSA 1024]----+

| |

| . . |

| = . . |

| o + = . . |

| = S o o |

| . + o E o o.|

| . . o o|

| ... . .|

| .o . o.|

+-----------------+


二、将公钥分发到服务器
使用ssh-copy-id -i username@hotname 分发

 

 

ssh-copy-id -i changhai@192.168.1.5

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

changhai@192.168.1.5's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'changhai@192.168.1.5'"

and check to make sure that only the key(s) you wanted were added.

 

 

 


三、测试链接
使用ssh命令连接服务器

ssh changhai@192.168.1.5

Welcome to Deepin 2014.2 (GNU/Linux 3.13.0-44-generic x86_64)

* Documentation: http://wiki.linuxdeepin.com/

------分隔线----------------------------
标签(Tag):
------分隔线----------------------------
推荐内容
猜你感兴趣