首页 > 其他分享 >ssh密钥免密登录仍需密码(排错及解决)

ssh密钥免密登录仍需密码(排错及解决)

时间:2023-08-16 19:23:17浏览次数:28  
标签:debug1 免密 排错 rsa etc host ssh key

目录

kali ssh免密登录靶机 vulnix,kali公钥信息放到靶机authorized_keys中后仍提示要输密码,在此记录解决方案。

报错信息:
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key

1.ssh

-v输出ssh过程的信息,与正常免密登录不同的是,还是要提示输入密码,结尾出现信息:
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password

┌──(root㉿wsec)-[/home/wsec/vulnix/nmap_result]
└─# ssh [email protected] -i /root/.ssh/id_rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -v
OpenSSH_9.3p2 Debian-1, OpenSSL 3.0.9 30 May 2023
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 192.168.80.177 [192.168.80.177] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type 0
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.3p2 Debian-1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: compat_banner: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH_5* compat 0x0c000002
debug1: Authenticating to 192.168.80.177:22 as 'vulnix'
debug1: load_hostkeys: fopen /root/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: ecdh-sha2-nistp256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: aes128-ctr MAC: [email protected] compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: [email protected] compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:IGOuLMZRTuUvY58a8TN+ef/1zyRCAHk0qYP4wMViOAg
debug1: load_hostkeys: fopen /root/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '192.168.80.177' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: /root/.ssh/id_rsa RSA SHA256:xsePVVaUFKhoWVauGIdyxsFs9eUsit4ez2/9VzZGT8A expli
cit
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /root/.ssh/id_rsa RSA SHA256:xsePVVaUFKhoWVauGIdyxsFs9eUsit4ez2/9VzZGT8A ex
plicit
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
[email protected]'s password:


2.尝试调试,看错误信息回显

//kali
ssh host@ip -p 4444

//靶机
/usr/sbin/sshd -d -p 4444

看到了报错信息:

Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key

┌──(root㉿wsec)-[/home/wsec/vulnix/nmap_result]
└─# ssh [email protected] -i /root/.ssh/id_rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -p 4444
ssh: connect to host 192.168.80.177 port 4444: Connection refused


vulnix@vulnix:~$ /usr/sbin/sshd -d -p 4444
debug1: sshd version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: could not open key file '/etc/ssh/ssh_host_rsa_key': Permission denied
Could not load host key: /etc/ssh/ssh_host_rsa_key
debug1: could not open key file '/etc/ssh/ssh_host_dsa_key': Permission denied
Could not load host key: /etc/ssh/ssh_host_dsa_key
debug1: could not open key file '/etc/ssh/ssh_host_ecdsa_key': Permission denied
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
debug1: setgroups() failed: Operation not permitted
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
debug1: rexec_argv[2]='-p'
debug1: rexec_argv[3]='4444'
Set /proc/self/oom_score_adj from 0 to -1000
debug1: Bind to port 4444 on 0.0.0.0.
Server listening on 0.0.0.0 port 4444.
debug1: Bind to port 4444 on ::.
Server listening on :: port 4444.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: inetd sockets after dupping: 3, 3
Connection from 192.168.80.148 port 53916
debug1: Client protocol version 2.0; client software version OpenSSH_9.3p2 Debian-1
debug1: match: OpenSSH_9.3p2 Debian-1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
debug1: list_hostkey_types:  [preauth]
No supported key exchange algorithms [preauth]
debug1: do_cleanup [preauth]
debug1: do_cleanup

3.解决方法

kali重新生成密钥文件,重启sshd服务

ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
y 回车

systemctl restart sshd

4.成功

-v -vvv 查看一些调试信息

┌──(root㉿wsec)-[/home/wsec/vulnix/nmap_result]
└─# ssh [email protected] -i /root/.ssh/id_rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -v
OpenSSH_9.3p2 Debian-1, OpenSSL 3.0.9 30 May 2023
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 192.168.80.177 [192.168.80.177] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type 0
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.3p2 Debian-1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: compat_banner: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH_5* compat 0x0c000002
debug1: Authenticating to 192.168.80.177:22 as 'vulnix'
debug1: load_hostkeys: fopen /root/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: ecdh-sha2-nistp256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: aes128-ctr MAC: [email protected] compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: [email protected] compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:IGOuLMZRTuUvY58a8TN+ef/1zyRCAHk0qYP4wMViOAg
debug1: load_hostkeys: fopen /root/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '192.168.80.177' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: /root/.ssh/id_rsa RSA SHA256:xsePVVaUFKhoWVauGIdyxsFs9eUsit4ez2/9VzZGT8A explicit
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /root/.ssh/id_rsa RSA SHA256:xsePVVaUFKhoWVauGIdyxsFs9eUsit4ez2/9VzZGT8A explicit
debug1: Server accepts key: /root/.ssh/id_rsa RSA SHA256:xsePVVaUFKhoWVauGIdyxsFs9eUsit4ez2/9VzZGT8A explicit
Authenticated to 192.168.80.177 ([192.168.80.177]:22) using "publickey".
debug1: channel 0: new session [client-session] (inactive timeout: 0)
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: Sending environment.
debug1: channel 0: setting env LANG = "zh_CN.UTF-8"
Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-29-generic-pae i686)

 * Documentation:  https://help.ubuntu.com/

  System information as of Sun Aug 13 14:43:16 BST 2023

  System load:  0.0              Processes:           97
  Usage of /:   85.4% of 773MB   Users logged in:     2
  Memory usage: 12%              IP address for eth0: 192.168.80.177
  Swap usage:   0%

  => / is using 85.4% of 773MB

  Graph this data and manage this system at https://landscape.canonical.com/

Your Ubuntu release is not supported anymore.
For upgrade information, please visit:
http://www.ubuntu.com/releaseendoflife

New release '14.04.6 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Sun Aug 13 14:03:40 2023 from 192.168.80.148
vulnix@vulnix:~$

4.其他

chmod 700 /root/.ssh (或尝试755)

chmod 700 /root/.ssh/authorized_keys

chmod 600 /root/.ssh/id_rsa

chmod 600 /root/.ssh/id_rsa.pub

-o IdentitiesOnly=yes
-o HostKeyAlgorithms=+ssh-rsa
-o PubkeyAcceptedKeyTypes=+ssh-rsa
-o PubkeyAcceptedAlgorithms=+ssh-rsa
-o HostkeyAlgorithms=+ssh-rsa

标签:debug1,免密,排错,rsa,etc,host,ssh,key
From: https://www.cnblogs.com/wsec/p/17635994.html

相关文章

  • ssh密钥免密登录仍需密码(排错及解决)
    目录ssh密钥免密登录仍需密码(排错及解决)1.ssh2.尝试调试,看错误信息回显3.解决方法4.成功4.其他ssh密钥免密登录仍需密码(排错及解决)kalissh免密登录靶机vulnix,kali公钥信息放到靶机authorized_keys中后仍提示要输密码,在此记录解决方案。报错信息:Couldnotloadhostkey:/et......
  • linux ssh 免密脚本
    #!/bin/baship="$1"pawd="123qwe!@#"expect<<EOFsettimeout10spawnssh-copy-id-p60022root@${ip}expect{       "yes/no"{send"yes\n";exp_continue}       "password:"{send"${pawd}\n"......
  • Windows服务器管理技巧:多用户登录设置、开启防火墙与SSH远程登录配置指南
    WindowsServer服务器管理技巧:对于使用WindowsServer服务器开发人员或者运维人员初学者来说,可能会遇到很多问题,比如:如何设置允许多用户同时登录服务器?如何开启服务器防火墙?Windows如何配置SSH远程登录?等等,如果遇到了这些问题,来看看这篇文章就能解决啦!一、如何设置允许多用户同时......
  • 禁用账号密码使用ssh私钥登录服务器
    1、生成ssh信息id_rsa为私钥,id_rsa.pub为公钥。私钥自己下载到本地电脑妥善保存(丢失后就无法再登陆了)建议删除服务器端的私钥。公钥则可以任意公开。ssh-keygen-trsa--------------------------------------输入生成的名称密码确认密码2、公钥导入到系统中cat/roo......
  • 修改ssh端口号
    Linux修改远程连接端口参考博客:Linux修改远程连接端口【解决方法】错误:无法和SFTP服务器建立FTP连接,请选择合适的协议修改远程连接端口1.编辑sshd配置,修改默认的端口。vi/etc/ssh/sshd_config找到配置端口号的位置,可在命令行模式下输入'?#Port22'进行查找。详细命令可......
  • CentOS 批量部署用户免密服务器
    一、前言在Linux系统中,SSH(SecureShell)是一种常用的远程登录和文件传输协议。传统的SSH登录需要输入用户密码,既不方便也不安全。为了解决这个问题,我们可以部署SSH的公钥认证,即免密登录。本文将详细介绍如何在CentOS上批量部署用户免密服务器。二、准备环境1台CentOS7.x的服务器(本......
  • 问题记录 <git push 到 github 时遇到 ssh 端口问题>
    问题描述gitpush时遇到如下问题:ssh:connecttohostgithub.comport22:Connectiontimedoutfatal:Couldnotreadfromremoterepository.解决方式通过修改端口得以解决,将22端口改为443,添加~/.ssh/config内容如下:Hostgithub.comHostnamessh.github.com......
  • openwrt dns ssh相关问题
    DHCP/DNS中的技术叫dnsmasq可配置hosts和自定义挟持域名配置image.pngimage.png拦截优先级为挟持域名最高,另外需要重启服务方可生效,在系统,启动项中重启dnsmasqssh使用root用户SSH登录服务器出现AccessDenied错误只输入root就出现了错误,但是输入其他......
  • SSH隧道代理实际操作指南
    在如今的互联网时代,许多网站和应用在某些地区受到限制和封锁,导致用户无法自由访问和享受在线资源。为了突破这一限制,SSH隧道代理成为了一种简单有效的工具。本文将详细介绍SSH隧道代理的原理、使用方法以及一些实际操作技巧,让您轻松畅游互联网。在介绍SSH隧道代理之前,我们先了解下S......
  • 利用ssh 隧道代理服务器本地端口,实现远程连接服务器本地数据库
    ssh隧道代理写这篇文章的原因是因为在开发中,遇到了需要对线上服务器数据进行调试,为方便在本地使用图形化工具。mysql,redis总所周知是不允许远程连接数据库的,我们就无法在本地对服务器数据进行调试。所以就可以利用ssh工具进行隧道代理本地调试数据。废话不多说直接开干,上代码......