发信人: hackerbay(阿土) 
整理人: sungang(2003-04-02 19:59:00), 站内信件
 | 
 
 
sshd2配置指要
 
 #sshd是商业化的ssh守护程序,漏洞比openssh少;
 #下载
 #ftp://ftp.ssh.com/pub/ssh
 #linux/freebsd下的服务端程序源码;
 ftp://ftp.ssh.com/pub/ssh/ssh-3.2.2.tar.gz
 #windows下的ssh客户端,一般来说,为了避免问题,尽量使用相同版本的服务端和客户端;
 ftp://ftp.ssh.com/pub/ssh/SSHSecureShellClient-3.2.2.exe
 
 1.服务端安装(linux为例)
 mkdir -p /usr/local/src/distfiles
 cd /usr/local/src/distfiles
 wget ftp://ftp.ssh.com/pub/ssh/ssh-3.2.2.tar.gz
 tar xfz ssh-3.2.2.tar.gz -C ..
 cd ../ssh-3.2.2
 ./confiure --help
 ./configure --without-ssh-agent1-compat --disable-debug --without-x11-security --without-internal-ssh1-compat --with-ssh-connection-limit=50 --without-ipv6 --with-libwrap
 make && make install
 #安装程序自动做了
 ln -s /usr/local/sbin/sshd2 /usr/local/sbin/sshd
 #new key
 #rm /etc/ssh2/hostkey*
 #/usr/local/bin/ssh-keygen2 –P /etc/ssh2/hostkey
 
 #使用新的sshd替代系统的openssh‘s sshd
 #系统默认的sshd启动脚本在/etc/init.d/sshd
 cp /etc/init.d/sshd /etc/init.d/sshd.openssh
 #vi /etc/init.d/sshd
 #!/bin/bash
 #
 
 # source function library
 . /etc/rc.d/init.d/functions
 
 # pull in sysconfig settings
 #[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
 
 RETVAL=0
 prog="/usr/local/sbin/sshd"
 
 # Some functions to make the below more readable
 KEYGEN=/usr/local/bin/ssh-keygen2
 SSHD=/usr/local/sbin/sshd
 PID_FILE=/var/run/sshd.pid
 
 start()
 {
         echo -n $"Starting $prog:"
         initlog -c "$SSHD $OPTIONS" && success || failure
         RETVAL=$?
         [ "$RETVAL" = 0 ] && touch /var/lock/subsys/sshd
         echo
 }
 
 stop()
 {
         echo -n $"Stopping $prog:"
         killproc $SSHD -TERM
         RETVAL=$?
         [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/sshd
         echo
 }
 
 reload()
 {
         echo -n $"Reloading $prog:"
         killproc $SSHD -HUP
         RETVAL=$?
         echo
 }
 
 case "$1" in
         start)
                 start
                 ;;
         stop)
                 stop
                 ;;
         restart)
                 stop
                 start
                 ;;
         reload)
                 reload
                 ;;
         status)
                 status $SSHD
                 RETVAL=$?
                 ;;
         *)
                 echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
                 RETVAL=1
 esac
 exit $RETVAL
 #end of /etc/init.d/sshd
 
 #FreeBSD版本
 #!/bin/sh
 #vi /usr/local/sbin/sshd2.sh
 case "$1" in
  
 start)
         if [ -x /usr/local/sbin/sshd2 ]; then
                 /usr/local/sbin/sshd2 && echo . && echo 'SSHD2 server started.'                                          
         fi
         ;;
  
 stop)
         killall -9 mpd && && echo . && echo 'SSHD2 server stopped.'     
         ;;
 restart)
         echo .
         echo Restart SSHD2 server ......     
         $0 stop
         sleep 5
         $0 start
         ;;
 *)
         echo "$0 start | stop | restart"
         ;;
  
 esac
 #end of /usr/local/sbin/sshd2.sh
 #设置可执行权限
 chmod 700 /usr/local/sbin/sshd2.sh
 #开机自动启动
 ln -s /usr/local/sbin/sshd2.sh /usr/local/etc/rc.d
 
 rc.conf里指定sshd_enable="NO"
 
 2.windows客户端配置;
 #使用windows下的SSH Secure Shell客户端连接
 #要求同样的版本3.20
 #首先使用密码验证方式登录,然后在SSH Secure Shell客户端,菜单->edit->setting
 #出来对话框:选择Global Settings ->User Authentication ->Keys
 #列出当前已经有的key,选择Generate New ...,出来向导
 #在key类型处建议使用2048位,DSA/RSA都行,DSA是开放源码的不要钱,RSA是商业算法,严格意义上是要付费的;
 #RSA的加密更强一点;
 #下一步开始创建密匙文件,根据你的机器性能差别,可能需要几分钟;
 #完成后,输入保存密匙的文件名,说明,以及一个额外的加密字,这个加密字是自定义的,不需要跟你的密码相同;
 #完成后,然后在SSH Secure Shell客户端,菜单->edit->setting
 #出来对话框:选择Profile Setting -> Authentication,在列出的Authencation methods中(一般只有Public Key和Password);
 #选择password,点Authencation methods右边的红叉叉,删除Password验证方式;
 #ok,现在你只能使用Public Key验证了;
 
 3.附加配置,在服务器上限制只能用key验证;
 #vi /etc/ssh2/sshd2_config
 ## Authentication
 ## publickey and password allowed by default
 
         AllowedAuthentications          publickey
 #此处限制只能使用key验证;        
 #       AllowedAuthentications          publickey,password
 
 4.在linux里生成登录用的key
 #登录成为某用户
 ssh-keygen2 -b 2048
 #会让用户输入加密字,跟密码不同;
 #自动生成下列文件
 
 #私人密匙,用于在linux里登录其他linux系统用;
 Private key saved to $HOME/.ssh2/id_dsa_2048_a
 
 echo "IdKey id_dsa_2048_a" >$HOME/.ssh2/identification
 #identification指定从本机登录其他系统时使用的私人密匙;
 
 #公开密匙,用于在其他系统登录本机用;
 Public key saved to $HOME/.ssh2/id_dsa_2048_a.pub
 
 echo "key id_dsa_2048_a.pub" >$HOME/.ssh2/authorization
 #authorization指定从别的系统登录本机时使用的public key;
 
 #如果你要从windows登录本机;
 #指定客户端可以使用这个key验证;
 把上述两个文件ftp或邮件传送回windows客户机里,导入到ssh客户端就可以用该public key登录了;
 
 #如果你要从本机(linux)用ssh2以key方式登录其他ssh2主机;
 #把公开密匙id_dsa_2048_a.pub传送到该主机你的主目录下的.ssh2目录里(如果不存在该目录,要先建立该目录);
 #在$HOME/.ssh2/authorization文件里添加一个key记录
 echo "key id_dsa_2048_a.pub" >>$HOME/.ssh2/authorization
 #现在你可以ssh2 remote_host了
 #ssh2会提示你输入加密字;
 
 
 
 
 
 
 
  ---- http://www.bsdbase.com
 Trust me, I know what I am doing !
 Give me a Fish I Eat For a day ;teach me to fish,I`ll eat for a life time. | 
 
 
 |