环境: Redhat

安装包:openssl-0.9.7b.tar.gz

openssh-3.6.1p1.tar.gz


步骤:
1. 上传解包两个tar.gz文件,以下过程是先编译openssl,再编译openssh。

2. cd openssl-0.9.7b

3. ./config

4. make clean

5. make

6. make install

这时,新的ssl库在/usr/local/ssl/

根据[url]www.openssl.org[/url]的说明,我不能将这些库覆盖掉系统原有的,否则...

URL:[url]http://www.openssl.org/support/faq.html#BUILD8[/url]


7. cd ../openssh-3.6.1p1

8. ./configure --with-ssl-dir=/usr/local/ssl

这一步是指出需要的库在/usr/local/ssl/

9. make

10. make install

恭喜,搞定了,如果没有error的话。

新安装默认的ssh服务器端程序是/usr/local/sbin/sshd

新安装默认的ssh客户端程序是/usr/local/bin/ssh

新安装默认的ssh配置文件在/usr/local/etc/


11. 备份!由于系统在安装时自带ssh,所以需要将新的文件覆盖掉原有的。

强烈建议先备份原有的文件,包括:

/usr/bin/ssh

/usr/sbin/sshd

/etc/ssh/*


12. useradd sshd

我不知道为什么,但一定要创建sshd用户,否则无法正常启动sshd服务。icon_sad.gif


13. 开始覆盖!需要进入linux单机模式,或在启动时不要启动sshd服务,否则/usr/sbin/sshd文件覆盖不了。icon_sad.gif

cp /usr/local/sbin/sshd /usr/sbin/sshd

cp /usr/local/bin/ssh /usr/bin/ssh

cp /usr/local/etc/* /etc/ssh/


14. 新安装的openssh还包括了sftp和scp两个应用程序,也可以覆盖掉系统原有的。

cp /usr/local/bin/sftp /usr/bin/sftp

cp /usr/local/bin/scp /usr/bin/scp


15. ssh -V

查询当前的版本,应该如下显示:

OpenSSH_3.6.1p1, SSH protocols 1.5/2.0, OpenSSL 0x0090702f


16. 用客户端连接主机,看是否有问题,正常的话,表求服务器程序正常工作;

在主机上执行ssh xx.xx.xx.xx,看是否连得上,正常表示服务器客户端正常工作。

 

 OpenSSH

为什么要用OpenSSH?
麦子在他写的那篇名为SSH的文章提到——使用telnet进行远程设备维护的时候,由于密码和通讯都是明文的,易受sniffer侦听,所以应采用SSH替代telnet。

为什么首先提安装OpenSSH而不是其他的是因为xxbin实在不愿意用机器的物理终端或者是telnet来操作机器。

OpenSSH是Linux/UNIX上用的最多的SSH Server,xxbin无论是在Linux/FreeBSD还是AIX上都用它,不过请大家注意,OpenSSH的低版本是有漏洞的,另外还有一点特别要小心——OpenSSH以及Apache(SSL Support)等所依靠的软件OpenSSL的低版本也存在一些漏洞的,因此,在安装OpenSSH以及Apache之前,需要安装最新版本的OpenSSL,切记切记,否则即使你安装了最新版本的Apache和OpenSSH,系统还是存在致命的漏洞!

首先安装OpenSSL:
从 [url]http://www.openssl.org/source/[/url] 下载最新版本的OpenSSL,在写这篇文章的时候,最新版本的OpenSSL为OpenSSL 0.9.7a

(在安装前请把系统中原来安装的旧的版本的openssl卸载掉)

tar -xvzf openssl-0.9.7a.tar.gz
cd openssl-0.9.7
./config shared
make
make test
make install

如果没有问题,那么OpenSSL就被安装在/usr/local/里面了,注意上面的配置命令里面有个shared,意思是创建Shared Libraries,这个选项一定要加上,否则某某程序报错说找不到某某so你就不要来找我。

另外,为了兼容某些程序比如OpenSSH,需要手动创建一些符号连接:
cd /usr/local/ssl/lib
ln -s libcrypto.so.0.9.7 libcrypto.so.2
ln -s libssl.so.0.9.7 libssl.so.2

最后要刷新系统的动态连接库配置
echo /usr/local/ssl/lib >> /etc/ld.so.conf
ldconfig -v

看看/usr/local/ssl/lib下是否存在下面两行:
libcrypto.so.0.9.7 -> libcrypto.so.0.9.7
libssl.so.0.9.7 -> libssl.so.0.9.7


接着安装OpenSSH:
从 [url]ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/[/url] 下载最新版本的OpenSSH,在写这篇文章的时候,最新版本的OpenSSH为OpenSSH 3.5 P1。

tar -xvzf openssh-3.5p1.tar.gz
cd openssh-3.5p1
./configure --with-ssl-dir=/usr/local/ssl
make
make install


注意查看configure的输出,找到有关OpenSSL的部分
类似:
checking OpenSSL header version... 90702f (OpenSSL 0.9.7b 10 Apr 2003)
checking OpenSSL library version... 90702f (OpenSSL 0.9.7b 10 Apr 2003)

看看是否应用了最新版本OpenSSL

如果没有问题,那么OpenSSH就被安装在/etc/local里面了,所有有关OpenSSH的配置文件都放在/usr/local/etc目录下,修改配置文件/usr/local/etc/sshd_config

vi /usr/local/etc/sshd_config

CODE 


# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.
Port 22
Protocol 2,1
ListenAddress 0.0.0.0

HostKey /usr/local/etc/ssh_host_key
HostKey /usr/local/etc/ssh_host_rsa_key
HostKey /usr/local/etc/ssh_host_dsa_key

SyslogFacility AUTH
LogLevel INFO

PermitRootLogin yes
RhostsAuthentication no
IgnoreRhosts yes

UsePrivilegeSeparation yes
Subsystem sftp /usr/local/libexec/sftp-server
 


这里面主要要改动的就是PermitRootLogin yes。


配置OpenSSH自启动:

cp contrib/redhat/sshd.init /etc/init.d/sshd
ln -s /etc/init.d/sshd /etc/rc.d/rc3.d/S55sshd

 

启动OpenSSH:

/etc/init.d/sshd start
若系统没有提示错误那就说明sshd已经起来了,可以ps -ef |grep sshd来确认一下,同时也可以用ssh客户端来测试一番。
若系统提示错误,就应该根据错误来进行排错,因为可能的错误实在太多,在这里就不做讨论了。


推荐采用的SSH客户端:
如果在Linux/UNIX下,那么用OpenSSH带的ssh客户端就OK了,如果在Windows下,强烈建议采用SecureCRT