Use ssh to change the default port number and implement password-free remote login.

Source: Internet
Author: User

Use ssh to change the default port number and implement password-free remote login.

Recently, I have reviewed the basic usage of the firewall management tool iptables, which involves adding or deleting firewall policies on ports. I am not familiar with the ssh method for changing the default port number and password-free logon, this is a basic summary.Prevent forgetting.

We hope you will spend a lot on error deviations and other experiences!

 

System Environment: Two RHEL 7 servers

Logon HOST: master.domain12.example.com 192.168.0.150/24

Remote Host: rhel.domain12.example.com 192.168.0.212/24

 

1. Change the default port number through ssh

Operation on rhel.domain12.example.com:

(1) configure the remote host ssh configuration file/Etc/ssh/sshd_config, Change the port number (Ensure that port 50000 is not occupied in advance).

 

(2) restart the ssh service, set Automatic startup, and view the process status.

Add the allowed CIDR blocks and port 50000 to the firewall policy and save them.

UseService iptables saveSave and write the configuration to the iptables configuration file./Etc/sysconfig/iptables, Otherwise the next boot willThis firewall policy is lost..

Use netstat-tunlp to view the status of port 50000.

 

2. ssh for password-free remote login

Operation on master.domain12.example.com:

(1) UseSsh-keygenCommand to generate the public/private key for remote logon. The public key is in the logon host and remote host, and the private key is in the logon host.Rsa AlgorithmThe generated public/private key.

 

(2) UseRsyncCommand to set the Public Key/Root/. ssh/id_rsa.pubSynchronize to remote host rhel.domain12.example.com/Root/. ssh.

Because the firewall policy has been cleared in the remote host, andOpen Port 50000 only, AndRsync uses ssh port 22 by default.Therefore, you must specify the rsync command to usePort 50000Synchronize the public key.

Used here-E Type SelectionTo implement the specified port,Enclose it in double quotation marks, The other syntax formats are the same as the general rsync command.

 

(3) view remote hosts/Root/. sshThe public key in the directory. Redirect the public keyAuthorized_keysFile, change the access permission of this fileRoot User Read-Only.

 

3. Test the ssh logon using the specified port and password-free

Log on to master.domain12.example.com directly,Successfully logged on.

-P OptionSpecify the port number for ssh login.

 

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.