LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1349|回复: 3

如何让SSH只允许密钥连接?

[复制链接]
发表于 2004-7-13 10:03:55 | 显示全部楼层 |阅读模式
我配置了服务器的  /etc/ssh/sshd_config
文件:

# Package generated configuration file
# See the sshd(8) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 600
PermitRootLogin no
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile        %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to no to disable s/key passwords
ChallengeResponseAuthentication yes

# Change to yes to enable tunnelled clear text passwords
PasswordAuthentication no


# To change Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#AFSTokenPassing no
#KerberosTicketCleanup no

# Kerberos TGT Passing does only work with the AFS kaserver
#KerberosTgtPassing yes

X11Forwarding no
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
KeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

Subsystem        sftp        /usr/lib/sftp-server

UsePAM yes


        并且在客户端制作了密钥。并放到服务器端的
用户目录下/.ssh/   改名为authorized_keys         (而且chmod 0644)

可是我ssh的时候并不检查密钥。。。只能基于口令的连接。。

向大家请教。谢谢
发表于 2004-7-13 12:21:25 | 显示全部楼层
用ssh -v 来登录看看.
发表于 2004-8-5 10:34:29 | 显示全部楼层
现在有两台主机为inno1,inno3(OS:redhat 9.0)(也可以在一台机器上实验)
                在inno1$HOME/.ssh上运行:
                        [inno-pdns@inno-1 inno-pdns]$mkdir .ssh;cd .ssh
                        [inno-pdns@inno-1 inno-pdns]$ssh-keygen -d -f yourfilename
                        [inno-pdns@inno-1 inno-pdns]$连续3个回车键, 这时候你可以看到在你的.ssh目录下有两个文件.
                                                        为:yourfilename  yourfilename.pub
                        [inno-pdns@inno-1 inno-pdns]$通过ftp把iyourfilename.pub上传到inno3的$HOME/.ssh/目录下
                                                        (一定要把ftp设置为ascii模式)
                在inno3上$HOME/.ssh目录上运行
                        [inno-pdns@inno-3 inno-pdns]$cat yourfilename.pub >> authorized_keys
                        [inno-pdns@inno-3 inno-pdns]$chmod go-w $HOME $HOME/.ssh
                        [inno-pdns@inno-3 inno-pdns]$chmod 600 authorized_keys
       
                则现在通国inno1登录
                        [inno-pdns@inno-1 inno-pdns]$ssh -v inno3(或者ip地址) 则可登录inno3的机器
                                        -v参数表示你用debug模式登录,如果出错可以看到具体信息.
                        [inno-pdns@inno-3 inno-pdns]$
               
                /etc/ssh/ssh_config,sshd_config可以保持默认设置.如果不行,也可以把以下几项打开
                                RSAAuthentication yes
                                PubkeyAuthentication yes
                                AuthorizedKeysFile      .ssh/authorized_keys
发表于 2011-1-25 18:46:54 | 显示全部楼层
UsePAM yes 注掉它
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表