AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1275549
Accepted
Sam T.
Sam T.
Asked: 2020-09-17 03:39:55 +0800 CST2020-09-17 03:39:55 +0800 CST 2020-09-17 03:39:55 +0800 CST

ssh:不能使用公钥认证

  • 772

我一直无法使用 pubkey 身份验证进行 ssh。我一直在设置一个新服务器,但它无法正常工作。

我对默认 sshd_config 的更改是这样设置的:

sed -i 's/#PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i 's/X11Forwarding.*/X11Forwarding no/' /etc/ssh/sshd_config

从服务器运行:

user@storage:~/.ssh$ sudo /usr/sbin/sshd -d -p 2222
debug1: sshd version OpenSSH_8.2, OpenSSL 1.1.1f  31 Mar 2020
debug1: private host key #0: ssh-rsa SHA256:nC8X55Nqg+Tl222a3FtJy304XPzIpEU9LwXxFB5iTa8
debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:DpGM4IpHZ4RVwH1AUhnle9Ts51y2vrgLFBtGC+sa1Ho
debug1: private host key #2: ssh-ed25519 SHA256:6//2szDkpcZRGEdamM0/kgvH5xYR19/pQmTrjtLSGNU
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
debug1: rexec_argv[2]='-p'
debug1: rexec_argv[3]='2222'
debug1: Set /proc/self/oom_score_adj from 0 to -1000
debug1: Bind to port 2222 on 0.0.0.0.
Server listening on 0.0.0.0 port 2222.
debug1: Bind to port 2222 on ::.
Server listening on :: port 2222.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: sshd version OpenSSH_8.2, OpenSSL 1.1.1f  31 Mar 2020
debug1: private host key #0: ssh-rsa SHA256:nC8X55Nqg+Tl222a3FtJy304XPzIpEU9LwXxFB5iTa8
debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:DpGM4IpHZ4RVwH1AUhnle9Ts51y2vrgLFBtGC+sa1Ho
debug1: private host key #2: ssh-ed25519 SHA256:6//2szDkpcZRGEdamM0/kgvH5xYR19/pQmTrjtLSGNU
debug1: inetd sockets after dupping: 3, 3
Connection from 192.168.1.10 port 34130 on 192.168.1.13 port 2222 rdomain ""
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
debug1: permanently_set_uid: 126/65534 [preauth]
debug1: list_hostkey_types: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519 [preauth]
debug1: SSH2_MSG_KEXINIT sent [preauth]
debug1: SSH2_MSG_KEXINIT received [preauth]
debug1: kex: algorithm: curve25519-sha256 [preauth]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256 [preauth]
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none [preauth]
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none [preauth]
debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth]
debug1: rekey out after 134217728 blocks [preauth]
debug1: SSH2_MSG_NEWKEYS sent [preauth]
debug1: Sending SSH2_MSG_EXT_INFO [preauth]
debug1: expecting SSH2_MSG_NEWKEYS [preauth]
debug1: SSH2_MSG_NEWKEYS received [preauth]
debug1: rekey in after 134217728 blocks [preauth]
debug1: KEX done [preauth]
debug1: userauth-request for user user service ssh-connection method none [preauth]
debug1: attempt 0 failures 0 [preauth]
debug1: userauth-request for user user service ssh-connection method publickey [preauth]
debug1: attempt 1 failures 0 [preauth]
debug1: userauth_pubkey: test pkalg ssh-ed25519 pkblob ED25519 SHA256:FSrXJhrKh9s4r+GzeZ2NE6Pkwdbp/LNChHNz0OP34jk [preauth]
debug1: temporarily_use_uid: 1000/1000 (e=0/0)
debug1: trying public key file /home/user/.ssh/authorized_keys
debug1: fd 4 clearing O_NONBLOCK
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 1000/1000 (e=0/0)
debug1: trying public key file /home/user/.ssh/authorized_keys2
debug1: Could not open authorized keys '/home/user/.ssh/authorized_keys2': No such file or directory
debug1: restore_uid: 0/0
Failed publickey for user from 192.168.1.10 port 34130 ssh2: ED25519 SHA256:FSrXJhrKh9s4r+GzeZ2NE6Pkwdbp/LNChHNz0OP34jk
debug1: userauth-request for user user service ssh-connection method publickey [preauth]
debug1: attempt 2 failures 1 [preauth]
debug1: userauth_pubkey: test pkalg ecdsa-sha2-nistp521 pkblob ECDSA SHA256:T62aYA0CM4ZkwiU6GffBRP0j5gP6Jjown8DF/pQsfAE [preauth]
debug1: temporarily_use_uid: 1000/1000 (e=0/0)
debug1: trying public key file /home/user/.ssh/authorized_keys
debug1: fd 4 clearing O_NONBLOCK
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 1000/1000 (e=0/0)
debug1: trying public key file /home/user/.ssh/authorized_keys2
debug1: Could not open authorized keys '/home/user/.ssh/authorized_keys2': No such file or directory
debug1: restore_uid: 0/0
Failed publickey for user from 192.168.1.10 port 34130 ssh2: ECDSA SHA256:T62aYA0CM4ZkwiU6GffBRP0j5gP6Jjown8DF/pQsfAE
Connection closed by authenticating user user 192.168.1.10 port 34130 [preauth]
debug1: do_cleanup [preauth]
debug1: monitor_read_log: child log fd closed
debug1: do_cleanup
debug1: Killing privsep child 72241
debug1: audit_event: unhandled event 12

我的 homedir、.ssh 和 authorized_keys 的相关权限:

drwxr-xr-x 18 user user 4096 Sep 16 07:31 user/
drwx------  2 user user 4096 Sep 16 07:31 .ssh/
-rw-r--r--  1 user user   96 Sep 16 06:42 authorized_keys

作为我设置的实验PasswordAuthentication yes,并且能够连接。此外,我还能够成功连接到使用 pubkey 身份验证(使用相同密钥)的另一台服务器,因此我知道客户端已正确设置密钥以供使用。

server ssh authentication
  • 1 1 个回答
  • 1805 Views

1 个回答

  • Voted
  1. Best Answer
    Sam T.
    2020-09-17T04:59:24+08:002020-09-17T04:59:24+08:00

    好的 - 我想通了......在我的authorized_keys文件顶部添加一个空行就可以了

    • 0

相关问题

  • 如何从命令行刻录双层 dvd iso

  • 如果在服务器机器上运行 Ubuntu 桌面版,性能损失是多少?

  • 将桌面版剥离为服务器版的最简单方法是什么?

  • 如何与无头服务器进行图形交互?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve