vmware虚拟centos上做ssh服务端,真机XP做客户端,只能用一个普通用户通过密钥登陆

Mr.noodles 发布于 2011/12/04 19:47
阅读 3K+
收藏 2

vmware虚拟机安装了个centos系统

yum install openssh

vi /etc/ssh/sshd_config




Port 22
Port 18439
Protocol 2
ServerKeyBits 1024
SyslogFacility AUTHPRIV
PermitRootLogin yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      ~/.ssh/authorized_keys
PermitEmptyPasswords no
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
UsePAM yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
X11Forwarding yes
Subsystem       sftp    /usr/libexec/openssh/sftp-server

接下来

adduser sshadmin

su - sshadmin

ssh-keygen -t rsa

回车

设个密码

到root下 su

用winscp把私钥考下来

用puttygen.exe把id_rsa转换为sshadmin.ppk

service sshd restart

用putty登陆

被拒

关闭防火墙和selinux

可以用证书登陆

但是另外建立一个用户,用同样的方法并且把新的id_rsa.pub追加到authorized_keys中也是被拒呢?

在新建了一个centos的虚拟机做客户机

yum install openssh

adduser sshclient

su - sshclient

ssh-keygen -t rsa

回车

回车(没设置密码)

su

关闭iptables和selinux

cd /home/sshclient/.ssh/

scp id_rsa.pub root@192.168.1.10:~/.ssh    //事先已经在服务端设了~/.ssh这个目录了

service sshd restart

到服务端

cd ~/.ssh

cat id_rsa.pub >> authorized_keys

service sshd restart

在客户端

ssh sshclient@192.168.1.10

又登陆不上,搞不懂是为什么

 

请各位大哥大姐给个解,小弟感激不尽

 

 

加载中
0
好威支有希
好威支有希

ip不对?

端口不对?

密码不对?

有防火墙?

ssh服务未启动?

0
Mr.noodles
Mr.noodles

引用来自“lgeeker”的答案

ip不对?

端口不对?

密码不对?

有防火墙?

ssh服务未启动?

ip没问题

XP的ip是192.168.1.1

sshclient的IP是192.168.1.2

sshadmin的IP是192.168.1.10

端口是22呀

密码很简单,不会有错

防火墙都是关了滴

sshd 正常启动

0
mark35
mark35
用同样的方法并且把新的id_rsa.pub追加到authorized_keys中也是被拒呢?
怎么个被拒法?
0
Mr.noodles
Mr.noodles

引用来自“mark35”的答案

用同样的方法并且把新的id_rsa.pub追加到authorized_keys中也是被拒呢?
怎么个被拒法?

谢谢mark35对问题的关注

客户端ssh_config和sshd_config未作任何的改动

#ssh  client1@192.168.1.1

这里会让我输入密钥的密码,输入后通过,但是后面还会让我输密码,我就不知道是个神马密码了,输什么都是denied

Client1@192.168.1.1`s  password:

Permition denied(publickey,gssapi-keyex,gssqpi-with-mic,password)

0
mark35
mark35

接下来 adduser sshadmin

su - sshadmin

ssh-keygen -t rsa

回车 设个密码

到root下 su -

我明白了。你只是给生成的RSA证书设定了口令,但未给 sshadmin这个用户设定(系统)口令吧?

# password sshadmin

sshd_config默认配置是不允许空口令账户登录的。你用证书SSH登录成功也输入了口令的,那个口令是验证证书的访问权限而不是验证系统账户,故是本地验证而不是远程主机验证

另外你可以使用 ssh-copy-id 命令把公钥自动复制到要登录的远程主机相应位置,而无需登录到远程主机上手动去修改authorized_keys文件。

 

 

 

0
Mr.noodles
Mr.noodles

谢谢mark35的解答

我明白了一些,但是我在做给sshadmin设置密码以后问题依旧

#ssh  client1@localhost.localdomain

(可以到localhost还是本地的不是远程的呀)

Client1@192.168.1.1`s  password:

Permintion denied ,please try againe.

Permintion denied ,please try againe.

Permintion denied ,please try againe.

Permition denied(publickey,gssapi-keyex,gssqpi-with-mic,password)

还忘指点一二,谢谢

0
Mr.noodles
Mr.noodles
重新做了好几遍了
0
mark35
mark35
scp id_rsa.pub root@192.168.1.10::~/.ssh //事先已经在服务端设了~/.ssh这个目录了

手动创建的? 必须保证这个 .ssh目录权限是 700!,其下文件权限必须是644.

 

0
mark35
mark35
AuthorizedKeysFile ~/.ssh/authorized_keys

我的和你似乎不同,用的是默认值(应该是 .ssh/authorized_keys)

 

#	$OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile	.ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

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

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

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

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing, 
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem	sftp	/usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	ForceCommand cvs server

 

 

返回顶部
顶部