In centos, the time limit for exit is set to the ip address logon shell script.

Source: Internet
Author: User
Tags ssh centos iptables

In the production environment, hosts may be modified by another administrator or user. allow allows more ip addresses to log on to machines. To facilitate unified management, you can change the allow and deny files to the default settings when exiting. At the same time, the whole ip segment of the machine's configured ip address can be automatically obtained to allow login.

Test-f/root/. bash_logout & chattr-I/root/. bash_logout
Cat>/root/. bash_logout <EOF
Export TERM = xterm
/Usr/bin/chattr-I/etc/hosts. allow/etc/hosts. deny

# For hosts. deny
/Bin/awk 'In in {FS = "[=.] "; RS =" \ n "};/^ IPADDR/{print" sshd: all records T "\ $2 ". "\ $3 ". "\ $4 ". 0/255. 255.255.0 "} '/etc/sysconfig/network-scripts/ifcfg-* | grep-v 127.0.0 | uniq 1>/etc/hosts. deny

/Bin/cat>/etc/hosts. deny <iEOF
Sshd: all forwarding t ip
IEOF

# For hosts. allow
/Bin/awk 'In in {FS = "[=.] "; RS =" \ n "};/^ IPADDR/{print" sshd: "\ $2 ". "\ $3 ". "\ $4 ". 0/255. 255.255.0 "} '/etc/sysconfig/network-scripts/ifcfg-* | grep-v 127.0.0 | uniq 1>/etc/hosts. allow

/Bin/cat>/etc/hosts. allow <iEOF
Sshd: ip
IEOF
/Usr/bin/chattr + I/etc/hosts. allow/etc/hosts. deny

Clear
EOF

Sh/root/. bash_logout 2> & 1>/dev/null

How to restrict ip addresses for ssh logon


Vi/etc/hosts. allow
Sshd: 192.168.0.100: allow // allow IP address 192.168.0.100 to log on
Sshd: 192.168.0.: allow // allow IP address 192.168.0. Network segment login
Sshd: all: deny // disable logon from all other IP addresses
Or
Sshd: 223.227.223. *: allow // allow IP 223.227.223. * network segment logon
Sshd: 192.168.0. *: allow // allow IP address 192.168.0. * network segment logon
Sshd: all: deny // disable logon from all other IP addresses
Save the changes under fedora and the changes will take effect.
FreeBSD restricts ssh login from specific ip addresses:
1.
# Ee/etc/hosts. allow
Add
Sshd: 192.168.0.100: allow
Sshd: 223.227.223. *: allow
Sshd: ALL: deny
2.
Modify/etc/ssh/sshd_config
Join
Allowusers admin@172.16.2.188
Indicates
Only allow admin to log on from 172.16.2.188

Change the IP address of FreeBSD without restarting the computer:
/Etc/netstart after modification in rc. conf

Iptables automatic IP address sealing script

#! /Bin/bash
# Created by haiyun
Num = 10 # upper limit
For I in 'awk'/Failed/{print $(NF-3 )} '/var/log/secure | sort | uniq-c | sort-rn | awk' {if ($1> $ num) {print $2 }}''
Do
Iptables-I input-p tcp-s $ I -- dport 22-j DROP
Done
Join crontab to schedule tasks
Crontab-e
**/5 *** sh/path/file. sh # execute once every 5 hours

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.