Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 通过公钥登录ssh密钥_Linux_Ssh - Fatal编程技术网

Linux 通过公钥登录ssh密钥

Linux 通过公钥登录ssh密钥,linux,ssh,Linux,Ssh,我正在使用公钥访问设置ssh,我想我已经正确配置了sshd_config并生成了id_rsa.pub和授权的_密钥 ssh-kengen -t rsa cd .ssh cat id_rsa.pub >> authorized_keys 我还设置了这些文件的权限 chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys 当我尝试sudo ssh localhost时,它可以工作,不需要密码,而是以root用户身份登录 但当我尝试ssh lo

我正在使用公钥访问设置ssh,我想我已经正确配置了sshd_config并生成了id_rsa.pub和授权的_密钥

ssh-kengen -t rsa
cd .ssh
cat id_rsa.pub >> authorized_keys
我还设置了这些文件的权限

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
当我尝试
sudo ssh localhost
时,它可以工作,不需要密码,而是以root用户身份登录

但当我尝试
ssh localhost
时,它仍然在询问密码

在此过程中生成的日志包括:-

OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/cwei/.ssh/identity type -1
debug1: identity file /home/cwei/.ssh/identity-cert type -1
debug1: identity file /home/cwei/.ssh/id_rsa type 1
debug1: identity file /home/cwei/.ssh/id_rsa-cert type -1
debug1: identity file /home/cwei/.ssh/id_dsa type -1
debug1: identity file /home/cwei/.ssh/id_dsa-cert type -1
debug1: identity file /home/cwei/.ssh/id_ecdsa type -1
debug1: identity file /home/cwei/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'localhost' is known and matches the RSA host key.
debug1: Found key in /home/cwei/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-
with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_604' not found
debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_604' not found
debug1: Unspecified GSS failure.  Minor code may provide more information
debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_604' not found
debug1: Next authentication method: publickey
debug1: Trying private key: /home/cwei/.ssh/identity
debug1: Offering public key: /home/cwei/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/cwei/.ssh/id_dsa
debug1: Trying private key: /home/cwei/.ssh/id_ecdsa
debug1: Next authentication method: password
cwei@localhost's password: 
OpenSSH_5.3p1,OpenSSL 1.0.1e-fips 2013年2月11日
debug1:读取配置数据/etc/ssh/ssh\u config
debug1:将选项应用于*
debug1:连接到本地主机[127.0.0.1]端口22。
debug1:已建立连接。
debug1:identity file/home/cwei/.ssh/identity-type-1
debug1:identity file/home/cwei/.ssh/identity-cert-type-1
debug1:identity file/home/cwei/.ssh/id\u rsa类型1
debug1:identity file/home/cwei/.ssh/id\u rsa-cert类型-1
debug1:identity file/home/cwei/.ssh/id_dsa type-1
debug1:identity file/home/cwei/.ssh/id_dsa-cert type-1
debug1:identity file/home/cwei/.ssh/id_ecdsa type-1
debug1:identity file/home/cwei/.ssh/id_ecdsa-cert type-1
debug1:远程协议版本2.0,远程软件版本OpenSSH_5.3
debug1:match:OpenSSH_5.3 pat OpenSSH*
debug1:启用协议2.0的兼容模式
debug1:本地版本字符串SSH-2.0-OpenSSH_5.3
debug1:SSH2\u MSG\u KEXINIT已发送
debug1:SSH2\u MSG\u KEXINIT已收到
debug1:kex:server->client aes128 ctr hmac-md5无
debug1:kex:客户端->服务器aes128 ctr hmac-md5无

debug1:SSH2\u MSG\u KEX\u DH\u GEX\u请求(1024Ssh公钥访问是基于用户的。可以为根用户进行配置。需要通过配置本地用户local.Ssh目录为本地用户进行配置。

您能提供创建
授权密钥的绝对路径吗?根用户的主文件夹是什么?Stackoverflow用于帮助检查您的密钥被拒绝的原因。也检查您的密钥被拒绝的原因。还要检查“代码”>授权的密钥KE/<代码>文件的权限,以确保它是正确的。授权的密钥的绝对路径是“代码> /home /cWei/.ssh/AuthixEdEdKEY < /COD>根用户的主页是<代码> /root 
。所有配置文件都在`
/etc/ssh/
下,我发现当我以
sudo/usr/sbin/sshd
的方式启动sshd时,它会工作,当我以
sudo/etc/init.d/sshd start
的方式启动sshd时,它会失败。我如何配置本地.ssh目录?通过将sshd_配置复制到.ssh?假设您有本地用户
chenwei
,以及
chenwei
的主目录是
/home/chenwei
,那么您应该将客户端的公钥(无需密码即可进行ssh登录)放入
/home/chenwei/.ssh/authorized_keys
文件中。您不需要复制sshd_配置文件。