SSH Security Configuration for CentOS

Source: Internet
Author: User
Tags ssh server dns spoofing

SSH is short for Secure Shell, developed by the Network Working Group of IETF. SSH is a security protocol built on the application layer and transport layer.

Traditional network service programs, such as FTP, POP, and Telnet, are inherently insecure because they transmit data, user accounts, and user passwords in plaintext over the network, attackers are vulnerable to man-in-the-middle attacks. There is another person or a machine impersonating a Real Server to receive data from the user to the server, and then impersonating the user to pass the data to the Real Server.

SSH is a reliable protocol designed for remote logon sessions and other network services. The SSH protocol can effectively prevent information leakage during Remote Management. SSH can be used to encrypt all transmitted data and prevent DNS Spoofing and IP spoofing.

System and version: CentOSrelease 5.3 (Final)

Install SSH

yum install ssh

Start SSH

service sshd start

Set startup

chkconfig sshd on

Modify SSH-related configuration files

First, modify the SSH configuration file. As follows:

[Root @ sample ~] # Vi/etc/ssh/sshd_config using vi open the SSH configuration file # Protocol locate this line and delete the line Header "#", and then delete ", 1" at the end of the line, only the connection Protocol 2 Protocol in SSH2 mode is allowed to be changed to this State after modification. Only the line "#" at the beginning of the line is found using SSH2 # ServerKeyBits 768 Protocol, change "768" to "1024 slave ServerKeyBits 1024 slave", and change "ServerKey strength" to "1024 bits # PermitRootLogin yes slave" to find this line and remove "#" at the beginning of the line, change "yes" to "no such PermitRootLogin no such modification" to this status. You are not allowed to log on using root. # PasswordAuthentication yes. Find this line, change "yes" to "no authorization PasswordAuthentication no authorization" and change it to this state. Password-based logon is not allowed # PermitEmptyPasswords no authorization. Find this line and delete "#" from the line header, you are not allowed to log on with a blank password.

Save and exit. (The command for saving and exiting vi is ZZ)

Because we only want to make the SSH service more convenient for the management system, we only allow the Intranet client to log on to the server through SSH without Remotely Managing the system over the Internet, to minimize unsafe factors. The setting method is as follows:

[Root @ sample ~] # Vi/etc/hosts. modify the deny shield rule and add the corresponding line at the end of the text # hosts. deny This file describes the names of the hosts which are # * not * allowed to use the local INET services, as decided # by the '/usr/sbin/tcpd' server. # The portmap line is redundant, but it is left to remind you that # the new secure portmap uses hosts. deny and hosts. allow. in particle # you shoshould know that NFS uses portmap! Sshd: ALL Users Add this line to shield all ssh connection requests [root @ sample ~] # Vi/etc/hosts. add the corresponding line at the end of the text # hosts. allow This file describes the names of the hosts which are # allowed to use the local INET services, as decided # by the '/usr/sbin/tcpd' server. # sshd: 192.168.0. ← add this line, only allow SSH connection requests from the Intranet

Restart SSH

After modifying the SSH configuration file, you must restart the SSH service to make the new settings take effect.

Root @ sample ~] #/Etc/rc. d/init. d/sshd restart SSH server Stopping sshd: [OK] Starting sshd: [OK] restart SSH server restart successful

At this time, on the remote terminal (Personal PC, etc.), you cannot log on to the server by using the SSH client software with a normal password. In order for the customer to log on to the server, we will create a public key and private key for SSH to log on to the SSH server as a "key" for the client.

Establishment of the public key and private key of SSH2

Logon is a general user who establishes a public key and a private key based on this user. (The following uses the centospub user as an example)

[Root @ sample ~] # Log on to the su-centospub guest as a general user centospub [centospub @ sample ~] $ Ssh-keygen-t rsa keys create public keys and private keys Generating public/private rsa key pair. enter file in which to save the key (/home/kaz /. ssh/id_rsa): name of the keystore key file. Press ENTER Created directory by default /. ssh 'enter passphrase (empty for no passphrase): Enter Your password Enter same passphrase again: Enter Your password again Your identification has been saved in/home/kaz /. ssh/id_rsa.Your public key has been saved in/home/kaz /. ssh/id_rsa.pub.The key fingerprint is: tf: rs: e3: 7 s: 28: 59: 5 s: 93: fe: 33: 84: 01: cj: 65: 3b: centospub@sample.centospub.com 8e

Then confirm the establishment of the public key and the key, and some processing corresponding to the client.

[Centospub @ sample ~] $ Cd ~ /. Enter the directory [centospub @ sample. ssh] $ ls-l keys list the files total 16-rw --- 1 centospub 951 Sep 4 id_rsa keys confirm that the private key has been created-rw-r-1 centospub 241 Sep 4 19: 22 id_rsa.pub confirm that the public key has been created [centospub @ sample. ssh] $ cat ~ /. Ssh/id_rsa.pub> ~ /. Ssh/authorized_keys export public key content to the corresponding file [centospub @ sample. ssh] $ rm-f ~ /. Ssh/id_rsa.pub keystore Delete the original public key file [centospub @ sample. ssh] $ chmod 400 ~ /. Ssh/authorized_keys secret set the attribute of the new public key file to 400

Then, the private key is securely transferred to the PC on which you want to connect to the server through SSH. The following uses a 3.5-inch disk as the media:

Centospub @ sample. ssh] $ exit quit normal user logon (return root logon) [root @ sample ~] # Mount/mnt/floppy/ephemeral mount the floppy drive [root @ sample ~] # Mv/home/centospub/. ssh/id_rsa/mnt/floppy/secrets move the created private key to a floppy disk [root @ sample ~] # Umount/mnt/floppy/uninstall detach a floppy disk drive

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.