use*_*594 428 ssh authorized-keys public-key
我将公共ssh密钥添加到authorized_keys文件中. ssh localhost应该登录我而不要求密码.
我这样做并尝试打字ssh localhost,但它仍然要求我输入密码.我还有其他任何设置可以让它运作吗?
我遵循了更改权限的说明:
如果我这样做,下面是结果 ssh -v localhost
debug1: Reading configuration data /home/john/.ssh/config
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/john/.ssh/identity type 1
debug1: identity file /home/john/.ssh/id_rsa type -1
debug1: identity file /home/john/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.7p1 Debian-8ubuntu3
debug1: match: OpenSSH_4.7p1 Debian-8ubuntu3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc 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/john/.ssh/known_hosts:12
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,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/john/.ssh/identity
debug1: Server accepts key: pkalg ssh-rsa blen 149
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Run Code Online (Sandbox Code Playgroud)
然后它在上面的日志之后要求passphase.如果没有密码,为什么不登录?
Ted*_*ddy 1045
您需要验证authorized_keys文件的权限以及文件所在的文件夹/父文件夹.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅此页面.
您可能还需要更改/验证主目录的权限,以删除该组和其他人的写访问权限.
chmod go-w ~
Run Code Online (Sandbox Code Playgroud)
Col*_*eld 148
SELinux也可能导致authorized_keys无法工作.特别是对于CentOS 6和7中的root.不需要禁用它.一旦您确认您的权限是正确的,您可以这样解决:
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
restorecon -R -v /root/.ssh
Run Code Online (Sandbox Code Playgroud)
bor*_*nac 96
设置ssh authorized_keys似乎很简单,但隐藏了一些我想要计算的陷阱
- 服务器 -
在/ etc/ssh/sshd_config中设置 passwordAuthentication yes为让服务器临时接受密码验证
- 客户 -
将 cygwin视为linux仿真并安装并运行openssh
1. 生成私钥和公钥(客户端)
# ssh-keygen
在这里只按ENTER,你会在〜/ .ssh /得到DEFAULT 2文件" id_rsa "和" id_rsa.pub ",但如果你给name_for_the_key,生成的文件会保存在你的pwd中
2.将your_key.pub放到目标计算机上ssh-copy-id user_name@host_name
如果你没有创建默认密钥,这是出错的第一步......你应该使用
ssh-copy-id -i path/to/key_name.pub user_name@host_name
3.日志记录ssh user_name@host_name仅适用于默认的id_rsa,因此这里有第二个陷阱ssh -i path/to/key_name user@host
(使用ssh -v ...选项查看发生的情况)
如果服务器仍然要求输入密码,那么你给了smth.以输入密码:当您创建密钥(所以这是正常的)
如果ssh没有监听默认端口22必须使用 ssh -p port_nr
- 服务器-----
4. 修改 的/ etc/SSH/sshd_config中有
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)
(如果是案件,则取消)
这告诉ssh接受authorized_keys并在用户主目录中查找用.ssh/authorized_keys文件写的key_name sting
5 在目标机器中设置权限
chmod 755 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)
同时关闭通过身份验证
passwordAuthentication no
关闭所有ssh root/admin /....@ your_domain尝试的大门
6确保所有非root主目录的所有权和组所有权是适当的.
chown -R ~ usernamehere
chgrp -R ~/.ssh/ user
Run Code Online (Sandbox Code Playgroud)
===============================================
7.考虑优秀的 http://www.fail2ban.org
8.额外的 ssh TUNNEL访问MySQL(bind = 127.0.0.1)服务器
Ste*_*yer 35
还要确保您的主目录不被其他人写入
chmod g-w,o-w /home/USERNAME
Run Code Online (Sandbox Code Playgroud)
绝望的人也可以确保他们在authorized_keys文件中没有额外的换行符,因为从混淆的终端复制了id_rsa.pub文本.
在.ssh/authorized_keys中列出公钥是必要的,但不足以让sshd(服务器)接受它.如果您的私钥受密码保护,则每次都需要为ssh(客户端)提供密码.或者你可以使用ssh-agent或gnome等价物.
您的UPDATE跟踪与受密码保护的私钥一致.请参阅ssh-agent或ssh-keygen -p.
用户是您的用户名
mkdir -p /home/user/.ssh
ssh-keygen -t rsa
touch /home/user/.ssh/authorized_keys
touch /home/user/.ssh/known_hosts
chown -R user:user /home/user/.ssh
chmod 700 /home/user/.ssh
chmod 600 /home/user/.ssh/id*
chmod 644 /home/user/.ssh/id*.pub
chmod 644 /home/user/.ssh/authorized_keys
chmod 644 /home/user/.ssh/known_hosts
Run Code Online (Sandbox Code Playgroud)
小智 5
最终对我起作用的是确保所有者/组不是root而是用户:
chown -R ~/.ssh/ user
chgrp -R ~/.ssh/ user
Run Code Online (Sandbox Code Playgroud)
在/var/log/auth.log服务器上的文件中查找sshd身份验证错误。
如果一切都失败了,那么sshd在调试模式下运行服务器:
sudo /usr/sbin/sshd -ddd -p 2200
Run Code Online (Sandbox Code Playgroud)
然后从客户端连接:
ssh user@host -p 2200
Run Code Online (Sandbox Code Playgroud)
就我而言,我在最后找到了错误部分:
debug1: userauth_pubkey: test whether pkalg/pkblob are acceptable for RSA SHA256:6bL+waAtghY5BOaY9i+pIX9wHJHvY4r/mOh2YaL9RvQ [preauth]
==> debug2: userauth_pubkey: disabled because of invalid user [preauth]
debug2: userauth_pubkey: authenticated 0 pkalg ssh-rsa [preauth]
debug3: userauth_finish: failure partial=0 next methods="publickey,password" [preauth]
debug3: send packet: type 51 [preauth]
debug3: receive packet: type 50 [preauth]
Run Code Online (Sandbox Code Playgroud)
有了这些信息,我意识到我的sshd_config文件限制了ssh组成员的登录。以下命令修复了此权限错误:
sudo usermod -a -G ssh NEW_USER
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
548507 次 |
| 最近记录: |