安装配置OpenSSH
1) 下载源代码安装包openssh-3.8p1.tar.gz,解压缩并进行编译安装:
[root@shuke src]#tar xvzf openssh-3.8p1.tar.gz
[root@shuke root]#cd openssh-3.8p1
[root@shuke openssh-3.8p1]#./configure --prefix=/usr/local/openssh --with-pam
[root@shuke openssh-3.8p1]#make
[root@shuke openssh-3.8p1]#make install
2) 安装完成后,为了支持普通密码认证,需要复制源代码树根目录下面的contrib/redhat/sshd.pam文件复制到/etc/pam.d目录:
[root@shuke openssh-3.8p1]#cp contrib/redhat/sshd.pam /etc/pam.d/sshd
3) 在远程客户端使用ssh命令登陆SSH服务器,如果是第一次登陆时,由于本地没有服务器的标示信息,因而显示不能建立连接:
[root@shuke1 root]#ssh -l wanghui 192.168.0.5
...
...
Are you sure you want to continue connecti ng (yes/no)?
4) 键入"yes"继续进行连接,则服务器的标识信息会记录在本地的ssh文件中,下次连接时不再询问相关信息:
...
...
Write failed: Broken pipe
5) 再次登陆,登陆成功:
[root@shuke1 root]#ssh -l wanghui 192.168.0.5
6) 为了使用密钥登陆验证,在客户端使用ssh-keygen命令生成密钥对:
[root@shuke1 root]#/usr/local/openssh/bin/ssh-keygen -d
...
...
The key fingerprint is:
...
7) 使用ftp连接到SSH服务器,并将/root/.ssh/id_dsa.pub公钥文件上载到服务器中,然后,在任一准备通过客户端登陆的用户的主目录(如:/home/wanghui)下,新建.ssh目录,把id_dsa.pub文件拷贝到该目录中;
8) 更改该文件的名称为authorized_keys2,并设置他的拥有者为该用户,权限为644:
[root@shuke .ssh]#mv ld_dsa.pub authorized_keys2
[root@shuke .ssh]#chown wanghui.wanghui authorized_keys2
[root@shuke .ssh]#chmod 644 authorized_keys2
9) 设置完成后,不需要重新启动服务器进程,在客户端再次使用ssh命令登陆服务器,则会出现要求输入提取密钥的密码:
[root@shuke1 root]#ssh -l wanghui 192.168.0.5
Enter passphrase for key '/root/.ssh/id_dsa':
10) 输入在上次生成密钥时输入的密码,ssh提取本地密钥进行密码验证,如果正确则登陆成功:
[root@shuke1 root]#ssh -l wanghui 192.168.0.5
Enter passphrase for key '/root/.ssh/id_dsa':
[root@shuke wanghui]$