Modify the ssh port in Linux and disable remote root logon.

Source: Internet
Author: User
Tags ssh port

Modify the ssh port in Linux and disable remote root logon.

Modify the ssh port and disable remote root login in Linux

We all know that the default ssh port number is 22. To change the port number to 9688, You need to edit the/etc/ssh/ssh_config and/etc/ssh/sshd_config files;
To disable remote root logon, edit/etc/ssh/sshd_config. (Some Linux directories may be/etc/sshd. Please modify them as needed)

The procedure is as follows:

1. Edit the/etc/ssh/ssh_config file:

[Root @ db02 ~] # Cat/etc/ssh/ssh_config | grep Port
Port 9688

Remove the comment symbol "#" before the commented-out Port 22, and change 22 to 9688 above. Save and exit.

2. Edit the/etc/ssh/sshd_config file:

# Vim/etc/ssh/sshd_config

Find PermitRootLogin and change "yes" to "no", so that the root user cannot log on remotely. Save and exit.

3. Restart ssh:

#/Etc/init. d/ssh restart

In this way, the ssh port number is successfully changed and root remote logon is disabled. It is worth mentioning that if your Linu x contains only root users, you must create a new user before disabling root remote logon, otherwise, ssh cannot be used to remotely log on to the server!

The content in this article is tested in Ubuntu. commands in other Linux systems are similar.

How does one change the SSH port in Linux?

Vi/etc/ssh/sshd_config, find Port 22, change Port 22 to the desired Port number, and restart the SSH service:/etc/init. d/sshd restart, and then test the ssh connection: ssh localhost-p your port number. The connection is successful. If you want to avoid using ssh connections because one port cannot be connected (for example, under attack), you can use multiple ssh connection ports, in the configuration file/etc/ssh/sshd_config, run vi/etc/ssh/sshd_config, find the Port, and add a line below: Port 23, in this way, a new connection port is added, the SSH service is restarted, and ssh localhost-p 23 is tested. The connection is successful. In addition, if the local test is normal, but you still cannot use the third-room tool to access the external SSH link, you need to disable the firewall and Restart SSHD. In this way, you can.

In linux, how does one Disable remote root login, and then use another account to log on to su root?

Ssh Modification


Set the default
# PermitRootLogin yes

Change the comment
PermitRootLogin no

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: 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.