OpenSSH is an implementation of the SSH protocol. it is a recommended security protocol for remote login, backup and remote file transmission through scp or sftp, SSH ensures the confidentiality and integrity of data exchange between two networks or systems. it implements server authentication through public key encryption technology. However, there are zero OpenSSH vulnerabilities
OpenSSH is an implementation of the SSH protocol. it is a recommended security protocol for remote login, backup and remote file transmission through scp or sftp, SSH ensures the confidentiality and integrity of data exchange between two networks or systems. it implements server authentication through public key encryption technology. However, the zero-day OpenSSH vulnerability is reported, so the OpenSSH server itself needs to be adjusted to improve overall security.
Default configuration file and SSH Port
/Etc/ssh/sshd_config: OpenSSH server configuration file;
/Etc/ssh/ssh_config: OpenSSH client configuration file;
~ /. Ssh/: User SSH configuration directory;
~ /. Ssh/authorized_keys: public key (RSA or DSA );
/Etc/nologin: If this file exists, sshd rejects logon from other users except root users;
/Etc/hosts. allow and/etc/hosts. deny: define the access control list executed by tcp-wrapper;
SSH default port: 22
Figure 1 SSH session window
1. disable the OpenSSH server
Workstation and laptop do not need OpenSSH servers. if you do not need to provide SSH remote logon and file transfer functions, you can disable and delete the SSHD server, centOS/RHEL/Fedora Linux users can use the following yum command to disable and delete openssh-server:
# Chkconfig sshd off # yum erase openssh-server
Debian/Ubuntu Linux users can use the following apt-get command to disable and delete openssh-server:
# Apt-get remove openssh-server
You may need to update your iptables script to remove ssh exception rules. in CentOS/RHEL/Fedora, open the etc/sysconfig/iptables and/etc/sysconfig/ip6tables files, delete the ssh-related exception rules and run the following command to restart iptables:
# Service iptables restart # service ip6tables restart
2. only use SSH v2
The first version of SSH protocol (SSH v1 or SSH-1) has man-in-the-middle attacks and security vulnerabilities that have been voided and should avoid using SSH v1 at all costs. Open the sshd_config configuration file, and add the following settings if not:
Protocol 2
After sshd is started, only the second version of the SSH protocol (SSH v2 or SSH-2) will be used.
3. restrict SSH access
By default, all system users can use their passwords or public keys to remotely log on through SSH. However, sometimes the UNIX/Linux users you create are for ftp or email purposes, without restrictions, these users can also log on to the system using ssh and use compilers, scripting languages, such as Perl or Python. these tools are of sufficient interest and can open any network port, perform any operation. An outdated PHP script exists on one of my clients. attackers can use the PHP script to create a new account in the system. However, attackers cannot log on to the client through ssh, because it is not within the permitted user list (AllowUsers ).
Assume that you only need the root, vivek, and jerry users to use the system via SSH and add the following to the sshd_config configuration file:
AllowUsers root vivek jerry
In addition, you can allow all users to log on via SSH, but reject some users. in this case, you need to add the following to the sshd_config configuration file:
DenyUsers saroj anjali foo
You can also configure Linux PAM to allow or deny logon through the sshd server. you can also specify a column of user groups that have the right to access or deny access to ssh.
4. configure the idle time-out exit interval
You can log on to the server through ssh. you can set an idle timeout interval to avoid orphan ssh sessions. open the sshd_config configuration file to ensure the following configuration items are available:
ClientAliveInterval 300 ClientAliveCountMax 0
In the preceding example, the idle timeout interval is set to 300 seconds, that is, 5 minutes. after this time, the idle user is automatically kicked out (which can be understood as logout or logout ).
5. disable the. rhosts file.
Do not read the user's ~ /. Rhosts and ~ /. Shosts file. use the following settings to update the sshd_config configuration file:
IgnoreRhosts yes
SSH can simulate outdated rsh commands. rsh is recognized as an insecure remote access protocol and must be disabled.
6. disable host-based authentication.
To disable host-based authentication, use the following options to update the sshd_config configuration file:
HostbasedAuthentication no
7. disable root logon through SSH
There is no need for a root user to remotely log on via SSH. common users can obtain root-level access through su or sudo (recommended), so that you can obtain complete audit information, it is clear who uses sudo to execute privileged commands on the system. To prevent the root user from logging on through SSH, use the following options to update the sshd_config configuration file:
PermitRootLogin no
However, some people think that it is okay for the root user to log on via SSH. the reason why "do not use the root user to log on" is that the Telnet protocol is not secure.
8. enable warning banners
Use the following settings to update the sshd_config configuration file and set a warning banner:
Banner/etc/issue
In the/etc/issue file, you can discuss with your legal counsel to list the laws, regulations and precautions that users should comply with when using ssh.
8. firewall SSH Port: 22
You need to update iptables or pf firewall configurations for ssh port 22. Generally, the OpenSSH server should only accept connections from the LAN or trusted remote clients.
Netfilter (iptables) configuration
Update the/etc/sysconfig/iptables (Red Hat and Red Hat-based system) file and only accept connections from 192.168.1.0/24 and 202.54.1.5/29. the configuration is as follows:
-A RH-Firewall-1-INPUT-s 192.168.1.0/24-m state -- state NEW-p tcp -- dport 22-j ACCEPT-A RH-Firewall-1-INPUT-s 202.54.1.5/29-m state -- state NEW-p tcp -- dport 22-j ACCEPT
If you want sshd to pass IP V6, you also need to update the/etc/sysconfig/ip6tables (Red Hat or Red Hat-based system) file. the configuration is as follows:
-A RH-Firewall-1-INPUT-s ipv6network:/ipv6mask-m tcp-p tcp -- dport 22-j ACCEPT
During actual operations, replace ipv6network:/ipv6mask with the actual IP address V6 address range.
◆ Bsd pf firewall configuration
If you are using the PF firewall, update the/etc/pf. conf file:
Pass in on $ ext_if inet proto tcp from {192.168.1.0/24,202.54 .1.5/29} to $ ssh_server_ip port
Ssh flags S/SA synproxy state
By default, ssh listens to all network adapters and IP addresses on the system, limits ssh Port binding, and changes ssh ports (brute-force attacks are usually targeted at Port 22 ), assume that you want to bind the IP addresses 192.168.1.5 and 202.54.1.5, and change the port to 300. then, modify the sshd_config file as follows:
Port 300
ListenAddress 192.168.1.5
ListenAddress 202.54.1.5
A better way is to use proactive scripts, such as fail2ban or denyhosts described later.
10. use strong SSH passwords and passwords
I won't talk about the importance of using strong user passwords and passwords for your keys. the reason why brute-force cracking attacks are successful is that you use a dictionary-based password, you can force users to avoid using words that can be directly found in the dictionary as passwords, and use the john the ripper tool to find weak passwords in the existing system. Below is a random password generator (put it in your ~ /. Bashrc file ):
Genpasswd () {local l = $1 ["$ l" = ""] & l = 20 tr-dc A-Za-z0-9 _ </dev/urandom | head-c $ {l} | xargs}
Run it:
Genpasswd 16
Output:
Uw8CnDVMwC6vOKgW
11. public key-based authentication
Use a public/private key pair and a password to protect the private key. for how to use identity authentication based on RSA and DSA, see html "> signature.
12. use key chain-based authentication
A key chain is a specially designed bash script that makes key-based authentication incredibly convenient and flexible. it has far more advantages than a key-less password. For how to install and use the key chain software, visit http://www.cyberciti.biz/faq/ssh-passwordless-login-with-keychain-for-scripts /.
13. Chroot SSHD (locking users in their own home directory)
By default, users can browse server directories, such as/etc and/bin. you can use a chroot based on the operating system or use special tools such as rssh to protect ssh, in OpenSSH 4.8p1 and 4.9p1, you no longer need third-party hack tools, such as rssh or complex chroot configurations, to restrict users to their own home directories, the new version adds a ChrootDirectory command, which can directly restrict users to their home directories. For more information, visit http://www.debian-administration.org/articles/590.
14. use TCP Wrapper
TCP Wrapper is a host-based network ACL system used to filter network access to the internet. OpenSSH supports TCP Wrapper and only needs to update your/etc/hosts. the following example shows that only ssh access from 192.168.1.2 and 172.16.23.12 is allowed:
192.168.1.2 172.16.23.12
For how to install and configure TCP Wrapper on Linux/Mac OS X and UNIX operating systems, visit http://www.cyberciti.biz/faq/tcp-wrappers-hosts-allow-deny-tutorial /.
15. disable empty passwords
You must explicitly disable remote logon for users with blank passwords.