软件:openssh-3.9p1.tar.gz
官方网站:http://www.openssh.com/
1.下载
# proz http://openbsd.md5.com.ar/pub/OpenBSD/Open...sh-3.9p1.tar.gz
2.安装
代码
# tar zxvf openssh-3.9p1.tar.gz
# ./configure --prefix=/opt/openssh
# make
#make install
3.修改配置文件
vi /opt/openssh/etc/sshd_config
代码
把
#Port 22
改成
Port 222 # 这里因为我自己的需要!
把
#Protocol 2,1
改成:
Protocol 2
把
#PermitRootLogin yes
改成:
PermitRootLogin no
这样就禁止了用户root直接登陆!
把
#PasswordAuthentication yes
改成:
PasswordAuthentication no
4.建立启动脚本[/opt/openssh/sshd]
cat > /opt/openssh/sshd
代码
#!/bin/bash
#
# Init file for OpenSSH server daemon
#
# chkconfig: 2345 55 25
# description: OpenSSH server daemon
#
# processname: sshd
# config: /etc/ssh/ssh_host_key
# config: /etc/ssh/ssh_host_key.pub
# config: /etc/ssh/ssh_random_seed
# config: /etc/ssh/sshd_config
# pidfile: /var/run/sshd.pid
# source function library
. /etc/rc.d/init.d/functions
# pull in sysconfig settings
[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
RETVAL=0
prog="sshd"
# Some functions to make the below more readable
KEYGEN=/opt/openssh/bin/ssh-keygen
SSHD=/opt/openssh/sbin/sshd
RSA1_KEY=/opt/openssh/etc/ssh_host_key
RSA_KEY=/opt/openssh/etc/ssh_host_rsa_key
DSA_KEY=/opt/openssh/etc/ssh_host_dsa_key
PID_FILE=/opt/openssh/sshd.pid
do_rsa1_keygen() {
if [ ! -s $RSA1_KEY ]; then
echo -n $"Generating SSH1 RSA host key: "
if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
chmod 600 $RSA1_KEY
chmod 644 $RSA1_KEY.pub
suclearcase/" target="_blank" >ccess $"RSA1 key generation"
echo
else
failure $"RSA1 key generation"
echo
exit 1
fi
fi
}
do_rsa_keygen() {
if [ ! -s $RSA_KEY ]; then
echo -n $"Generating SSH2 RSA host key: "
if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
chmod 600 $RSA_KEY
chmod 644 $RSA_KEY.pub
success $"RSA key generation"
echo
else
failure $"RSA key generation"
echo
exit 1
fi
fi
}
do_dsa_keygen() {
if [ ! -s $DSA_KEY ]; then
echo -n $"Generating SSH2 DSA host key: "
if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
chmod 600 $DSA_KEY
chmod 644 $DSA_KEY.pub
success $"DSA key generation"
echo
else
failure $"DSA key generation"
echo
exit 1
fi
fi
}
do_restart_sanity_check()
{
$SSHD -t
RETVAL=$?
if [ ! "$RETVAL" = 0 ]; then
failure $"Configuration file or keys are invalid"
echo
fi
}
start()
{
# Create keys if necessary
do_rsa1_keygen
do_rsa_keygen
do_dsa_keygen
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
;;
condrestart)
if [ -f /var/lock/subsys/sshd ]; then
do_restart_sanity_check
if [ "$RETVAL" = 0 ]; then
stop
# avoid race
sleep 3
start
fi
fi
;;
status)
status $SSHD
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
赋予可执行权限:# chmod u+x /opt/openssh/sshd
启动SSH
# chmod u+x /opt/openssh/sshd start
5.配置SSH客户端
使用下列步骤来为 SSH 协议的版本 2 生成 RSA 钥匙对。从 OpenSSH 2.9 开始,它已成为默认设置。
(1)要生成 RSA 钥匙对与协议的版本 2 合作,在 shell 提示下键入下列命令:
代码
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ourlinux/.ssh/id_rsa):
Created directory '/home/ourlinux/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ourlinux/.ssh/id_rsa.
Your public key has been saved in /home/ourlinux/.ssh/id_rsa.pub.
The key fingerprint is:
1a:00:46:93:bf:03:89:30:a5:a0:d5:c8:4f:25:f6:bc ourlinux@bixuan
接受 ~/.ssh/id_rsa 的默认位置。输入一个与你的帐号口令不同的口令句,再输入一次来确认。
公钥被写入 ~/.ssh/id_rsa.pub。密钥被写入 ~/.ssh/id_rsa。决不能把密钥出示给任何人。
(2)使用以下命令改变你的 .ssh 目录的许可权限:
代码
$ chmod 755 ~/.ssh
(3)把 ~/.ssh/id_rsa.pub 的内容复制到你想连接的机器上的 ~/.ssh/authorized_keys 文件中。如果 ~/.ssh/authorized_keys 不存在,你可以把 ~/.ssh/id_rsa.pub 文件复制到那个机器上的 ~/.ssh/authorized_keys 文件中。
(4)使用以下命令改变你的 authorized_keys 文件的许可权限:
代码
$ chmod 644 ~/.ssh/authorized_keys
6.测试连接
$ ssh -2 -p 222 IP
# 这里的-2表示用版本2,这里可以不用指定,以为已经是版本2了,只是为了说明的清楚点 -p 222表示连接端口是:222
The authenticity of host 'xxx.xxx.xxx.xx (xxx.xxx.xxx.xx)' can't be established.
RSA key fingerprint is 5e:39:69:5e:0b:56:23:63:b0:ce:5d:7c:37:e5:f5:28.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'xxx.xxx.xxx.xx' (RSA) to the list of known hosts.
Enter passphrase for key '/home/ourlinux/.ssh/id_rsa':
Last login: Mon Jan 10 03:35:06 2005 from xxx.xxx.xxx.xx
7.常见问题
(1)如果出现Permission denied (publickey,keyboard-interactive).
A.请先检查是否存在~/.ssh/authorized_keys并且~/.ssh/authorized_keys的权限是否是644,还有~./ssh是否是755的权限
B.请检查该用户是否没有设置passwd,如果没有,请用root用户先设置密码!这里是:
#passwd ourlinux,然后输入2次密码!
(2)配置客户端请安照步骤来配置!否则可能也会出现(1)的问题!
(3)我要在WIN上的SSH客户端软件来使用怎么办?
首先要把id_rsa id_rsa.pub下载到WIN的机器上来!
下面用SecureCRT来做客户端测试
如图1(见下面的附件)
8.注意点
要保存好id_rsa(密钥)和id_rsa.pub(公钥),尤其是密钥!
如果在配置过程中有问题,请回帖!或者在MSN联系:bixuan@linuxfans.org,同时也希望请大虾们赐教,先谢过
本文地址:http://www1.ourlinux.net/bbs/showforum.php...p?showtopic=190,转载请注名来自:碧轩居 - http://www.ourlinux.net
附图