2020年4月14日火曜日

ssh 無通信で切断されてしまう。ssh IP制限

# vi /etc/ssh/sshd_config
# add by takahab
ClientAliveInterval 120
ClientAliveCountMax 3


sshで繋らなくなった。
kex_exchange_identification: read: Connection reset by peer


# vi /etc/hosts.allow
sshd: 127.0.0.1
sshd: xxx.xxx.xxx.xxx
sshd: .jp                              ←これを追加で解決


【ssh IP制限】
# cat /var/log/secure* | grep 'Accepted publickey' | awk '{ print $11}' | sort | uniq -c | sort -r
# cat /var/log/secure* | grep 'Invalid user' | awk '{ print $10}' | sort | uniq -c | sort -r
# cat /var/log/secure* | grep 'refused connect' | awk '{ print $10}' | sort | uniq -c | sort -r

# cat /var/log/secure* |grep 'Invalid user' | awk 'match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { print substr($0, RSTART, RLENGTH) }'|uniq -c |sort

# for i in `cat /var/log/secure* |grep from | awk 'match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { print substr($0, RSTART, RLENGTH) }'|uniq -c |sort` ;do whois $i |grep country; done|sort |uniq -c

#  whois  [IP address] | grep country

# cat /var/log/ssh/sshd.log | grep 'Accepted publickey' | awk '{ print $7 $9}' | sort | uniq -c | sort -r
# cat /var/log/ssh/sshd.log | grep 'Invalid user' | awk '{ print $7}' | sort | uniq -c | sort -r
# cat /var/log/ssh/sshd.log | grep 'refused connect' | awk '{ print $7}' | sort | uniq -c | sort -r


# /etc/hosts.deny
sshd : all
or
ALL : ALL

# /etc/hosts.allow
sshd : 202.229.102.0/255.255.255.0
sshd : 202.229.102.

sshd : 218.221.32.0/255.224..0
sshd : 218.221.32.

sshd : 180.0.0.0/255.192.0.0

sshd: 202.229.102.0/255.255.255.0,218.221.32.0/255.255.224.0,180.0.0.0/255.192.0.0

sshd: *.casio.co.jp, *.cxdnext.co.jp \
            *.so-net.ne.jp

 

0 件のコメント:

コメントを投稿

zabbix7 amazon linux2023 インストール postgres15

【postgres】 dnf -y install postgresql15-server postgresql15-server-devel postgresql-setup initdb passwd postgres vi `find / -name pg_hba.con...