SSH服务和Telnet服务一样,通过远程登录登录到系统,在远程操控系统。但它与Telnet的不同点就是:Telnet在传输的过程中是平文传输,而SSH是将传输内容加密,在传送的过程中保证了传送内容的保密性,从而提高了系统的安全性。
在这里,我们不准备将SSH服务作为用户上传下载文件的工具。我们只用SSH服务的开通为远程管理系统提供方便。另外在用户认证方式上,为了服务器和用户的安全,禁止用户密码的认证方式,而基于“钥匙”的方式。
SSH相关配置文件的修改
首先修改SSH的配置文件。如下:
[root@centos5 ~]# vi /etc/ssh/sshd_config
Protocol 2 (仅使用SSH2)
PermitRootLogin no (不允许root用户使用SSH登陆)
ServerKeyBits 1024 (将serverkey的强度改为1024)
PasswordAuthentication no (不允许使用密码方式登陆)
PermitEmptyPasswords no (禁止空密码进行登陆)
[root@centos5 ~]# vi /etc/hosts.deny
#添加
sshd: ALL (拒绝所有的sshd请求)
[root@centos5 ~]# vi /etc/hosts.allow
#添加
sshd: 192.168.0.1 (允许主机192.168.0.1/24的sshd请求)
[root@centos5 ~]# /etc/rc.d/init.d/sshd restart (重启ssh服务)
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
[root@centos5 ~]# su - user1
[user1@centos5 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa): (目录默认为用户的家目录)
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase): (用于保护密钥的密码)
Enter same passphrase again: (两次的密码需要一样,且大于4个字符)
Your identification has been saved in /home/user1/.ssh/id_rsa. (私钥的存放位置)
Your public key has been saved in /home/user1/.ssh/id_rsa.pub. (公钥的存放位置)
The key fingerprint is:
9e:47:c2:b3:d5:b9:b0:9a:52:04:5d:81:56:98:b2:98 user1@centos5
[user1@centos5 ~]$ cd .ssh/ (将私钥文件导入到~/.ssh/authorized_keys文件中)
[user1@centos5 .ssh]$ ll
total 16
-rw------- 1 user1 user1 1743 Feb 1 00:47 id_rsa
-rw-r--r-- 1 user1 user1 395 Feb 1 00:47 id_rsa.pub
[user1@centos5 .ssh]$ cat ./id_rsa.pub >> ~/.ssh/authorized_keys
[user1@centos5 .ssh]$chmod 400 authorized_keys(将authorized_keys文件的权限设置为400)
使用putty密钥生成器(puttygen.exe)将复制下来的私钥生成putty可以使用的密钥
在putty登录
login as: user1
Authenticating with public key "imp
Passphrase for key "imp
[user1@centos5 ~]$ (成功登陆)
参见:http://hi.baidu.com/naruto6006/blog/item/c4c39ccdeb034e1700e92866.html