狂自私

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

伪·ssh能登录服务器,但是sftp不能登录

问题现象

生产环境共计19台服务器,处于内网隔离环境中,通过堡垒机登录使用。所有的服务器都能通过堡垒机使用ssh连接使用,但是只有其中一台能够sftp,其它的服务器都不能通过堡垒机使用sftp;

问题原因

堡垒机的IP地址没有加入到Linux的ip白名单中。

原因发现记录

按照网络上搜索出来的结果:

1、我对比了所有服务器的sshd_config配置文件内容,发现内容都是一致的

2、检查sftp子系统的可执行文件的权限:发现也都是755权限,不存在0权限的问题

然后我给sftp加上日志记录:

/etc/ssh/sshd_config文件:

[aduser@emqx-001 ~]sudo cat /etc/ssh/sshd_config |grep -v "^#"|grep -v "^"

Port 10022

HostKey /etc/ssh/ssh_host_rsa_key

HostKey /etc/ssh/ssh_host_ecdsa_key

HostKey /etc/ssh/ssh_host_ed25519_key

SyslogFacility AUTHPRIV

LogLevel DEBUG3

PermitRootLogin no

AuthorizedKeysFile      .ssh/authorized_keys

PasswordAuthentication yes

ChallengeResponseAuthentication no

GSSAPIAuthentication no

GSSAPICleanupCredentials no

UsePAM yes

X11Forwarding yes

UseDNS no

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

Subsystem       sftp    /usr/libexec/openssh/sftp-server -l DEBUG3 -f local5

[aduser@emqx-001 ~]$

在/etc/rsyslog.conf文件最后加入一行:auth,authpriv.*,local5.*,/var/log/sftp.log

重启sshd和rsyslog服务:

sudo systemctl restart rsyslog sshd

 

然后尝试sftp登录,抓取日志如下:

fd 5 is not O_NONBLOCK

Forked child 47874.

send_rexec_state: entering fd = 8 config len 769

ssh_msg_send: type 0

send_rexec_state: done

oom_adjust_restore

Set /proc/self/oom_score_adj to 0

rexec start in 5 out 5 newsock 5 pipe 7 sock 8

inetd sockets after dupping: 3, 3

Connection refused by tcp wrapper

connect from 22.62.20.6 (22.62.20.6)

然后确定了是因为/etc/hosts.deny和/etc/hosts.allow文件内容的原因,打开这两个文件,发现/etc/hosts.deny里面是拒绝所有的连接;而/etc/hosts.allow里面写了几行内容,看了下ip地址,没有22.62.20.6这个ip。将其加上并保存,重新尝试sftp,本次顺利登录上了。

posted on   狂自私  阅读(621)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2023-02-28 C++ 监听指定的按键后结束自己
点击右上角即可分享
微信分享提示