How to configure Linux sshd_config

May 14, 2023 pm 10:13 PM
linux sshd_config

[Note] Values ​​are case-sensitive, but instructions are case-independent.

1. Regarding the overall settings of the ssh server, including the port used and the password calculation method used

port 22          # ssh 预设使用 22 这个 port,您也可以使用多的 port !
              # 亦即重复使用 port 这个设定项目即可!
protocol 2,1        # 选择的 ssh 协议版本,可以是 1 也可以是 2 ,
              # 如果要同时支持两者,就必须要使用 2,1 这个分隔了!
#listenaddress 0.0.0.0   # 监听的主机适配卡!举个例子来说,如果您有两个 ip,
              # 分别是 192.168.0.100 及 192.168.2.20 ,那么只想要
              # 开放 192.168.0.100 时,就可以写如同下面的样式:
listenaddress 192.168.0.100          # 只监听来自 192.168.0.100 这个 ip 的ssh联机。
                   # 如果不使用设定的话,则预设所有接口均接受 ssh
pidfile /var/run/sshd.pid      # 可以放置 sshd 这个 pid 的档案!左列为默认值
logingracetime 600     # 当使用者连上 ssh server 之后,会出现输入密码的画面,
              # 在该画面中,在多久时间内没有成功连上 ssh server ,
              # 就断线!时间为秒!
compression yes      # 是否可以使用压缩指令?当然可以啰!
Copy after login

 
2. Explain where the private key of the host is placed File, by default use the file below!

hostkey /etc/ssh/ssh_host_key    # ssh version 1 使用的私钥
hostkey /etc/ssh/ssh_host_rsa_key  # ssh version 2 使用的 rsa 私钥
hostkey /etc/ssh/ssh_host_dsa_key  # ssh version 2 使用的 dsa 私钥
# 2.1 关于 version 1 的一些设定!
keyregenerationinterval 3600     # 由前面联机的说明可以知道, version 1 会使用
                   # server 的 public key ,那么如果这个 public
                   # key 被偷的话,岂不完蛋?所以需要每隔一段时间
                   # 来重新建立一次!这里的时间为秒!
serverkeybits 768           # 没错!这个就是 server key 的长度!
Copy after login


3. Regarding the placement of information data in the login file and the name of the daemon!

syslogfacility auth         # 当有人使用 ssh 登入系统的时候,ssh会记录资
                   # 讯,这个信息要记录在什么 daemon name 底下?
                   # 预设是以 auth 来设定的,即是 /var/log/secure
                   # 里面!什么?忘记了!回到 linux 基础去翻一下
                   # 其它可用的 daemon name 为:daemon,user,auth,
                   # local0,local1,local2,local3,local4,local5,
loglevel info            # 登录记录的等级!嘿嘿!任何讯息!
                   # 同样的,忘记了就回去参考!
Copy after login


4. Security setting items! Very important!
4.1 Login setting part

permitrootlogin no     # 是否允许 root 登入!预设是允许的,但是建议设定成 no!
userlogin no        # 在 ssh 底下本来就不接受 login 这个程序的登入!
strictmodes yes      # 当使用者的 host key 改变之后,server 就不接受联机,
              # 可以抵挡部分的木马程序!
#rsaauthentication yes   # 是否使用纯的 rsa 认证!?仅针对 version 1 !
pubkeyauthentication yes  # 是否允许 public key ?当然允许啦!只有 version 2
authorizedkeysfile      .ssh/authorized_keys
              # 上面这个在设定若要使用不需要密码登入的账号时,那么那个
              # 账号的存放档案所在档名!
Copy after login


4.2 Authentication part

rhostsauthentication no  # 本机系统不止使用 .rhosts ,因为仅使用 .rhosts 太
              # 不安全了,所以这里一定要设定为 no !
ignorerhosts yes      # 是否取消使用 ~/.ssh/.rhosts 来做为认证!当然是!
rhostsrsaauthentication no # 这个选项是专门给 version 1 用的,使用 rhosts 档案在
              # /etc/hosts.equiv配合 rsa 演算方式来进行认证!不要使用
hostbasedauthentication no # 这个项目与上面的项目类似,不过是给 version 2 使用的!
ignoreuserknownhosts no  # 是否忽略家目录内的 ~/.ssh/known_hosts 这个档案所记录
              # 的主机内容?当然不要忽略,所以这里就是 no 啦!
passwordauthentication yes # 密码验证当然是需要的!所以这里写 yes 啰!
permitemptypasswords no  # 若上面那一项如果设定为 yes 的话,这一项就最好设定
              # 为 no ,这个项目在是否允许以空的密码登入!当然不许!
challengeresponseauthentication yes  # 挑战任何的密码认证!所以,任何 login.conf
                   # 规定的认证方式,均可适用!
#pamauthenticationviakbdint yes      # 是否启用其它的 pam 模块!启用这个模块将会
                   # 导致 passwordauthentication 设定失效!
Copy after login


 
4.3 Parameter settings related to kerberos! Because we don’t have a kerberos host, there is no need to set it up!

#kerberosauthentication no
#kerberosorlocalpasswd yes
#kerberosticketcleanup yes
#kerberostgtpassing no
Copy after login


 
4.4 Below are the relevant settings for use under x-window!

x11forwarding yes
#x11displayoffset 10
#x11uselocalhost yes
Copy after login


4.5 Items after login:

printmotd no              # 登入后是否显示出一些信息呢?例如上次登入的时间、地点等
             # 等,预设是 yes ,但是,如果为了安全,可以考虑改为 no !
printlastlog yes     # 显示上次登入的信息!可以啊!预设也是 yes !
keepalive yes       # 一般而言,如果设定这项目的话,那么 ssh server 会传送
             # keepalive 的讯息给 client 端,以确保两者的联机正常!
             # 在这个情况下,任何一端死掉后, ssh 可以立刻知道!而不会
             # 有僵尸程序的发生!
useprivilegeseparation yes # 使用者的权限设定项目!就设定为 yes 吧!
maxstartups 10      # 同时允许几个尚未登入的联机画面?当我们连上 ssh ,
             # 但是尚未输入密码时,这个时候就是我们所谓的联机画面啦!
             # 在这个联机画面中,为了保护主机,所以需要设定最大值,
             # 预设最多十个联机画面,而已经建立联机的不计算在这十个当中
Copy after login


4.6 Setting items about user resistance:

denyusers *        # 设定受抵挡的使用者名称,如果是全部的使用者,那就是全部
             # 挡吧!若是部分使用者,可以将该账号填入!例如下列!
denyusers test
denygroups test      # 与 denyusers 相同!仅抵挡几个群组而已!
Copy after login


5. About the setting items of sftp service!

subsystem       sftp    /usr/lib/ssh/sftp-server
Copy after login

Basically, unless necessary, please do not change the settings of the /etc/ssh/sshd_config file in the system! Because the default ssh protection is usually the strictest, so there is no need to change it! The above description is just to let you understand some basic content of each item! What needs attention is the last item. If you are not willing to open sftp, just comment out the last line.

The above is the detailed content of How to configure Linux sshd_config. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is Linux actually good for? What is Linux actually good for? Apr 12, 2025 am 12:20 AM

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

How to start apache How to start apache Apr 13, 2025 pm 01:06 PM

The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

What to do if the apache80 port is occupied What to do if the apache80 port is occupied Apr 13, 2025 pm 01:24 PM

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

How to monitor Nginx SSL performance on Debian How to monitor Nginx SSL performance on Debian Apr 12, 2025 pm 10:18 PM

This article describes how to effectively monitor the SSL performance of Nginx servers on Debian systems. We will use NginxExporter to export Nginx status data to Prometheus and then visually display it through Grafana. Step 1: Configuring Nginx First, we need to enable the stub_status module in the Nginx configuration file to obtain the status information of Nginx. Add the following snippet in your Nginx configuration file (usually located in /etc/nginx/nginx.conf or its include file): location/nginx_status{stub_status

How to start monitoring of oracle How to start monitoring of oracle Apr 12, 2025 am 06:00 AM

The steps to start an Oracle listener are as follows: Check the listener status (using the lsnrctl status command) For Windows, start the "TNS Listener" service in Oracle Services Manager For Linux and Unix, use the lsnrctl start command to start the listener run the lsnrctl status command to verify that the listener is started

How to set up a recycling bin in Debian system How to set up a recycling bin in Debian system Apr 12, 2025 pm 10:51 PM

This article introduces two methods of configuring a recycling bin in a Debian system: a graphical interface and a command line. Method 1: Use the Nautilus graphical interface to open the file manager: Find and start the Nautilus file manager (usually called "File") in the desktop or application menu. Find the Recycle Bin: Look for the Recycle Bin folder in the left navigation bar. If it is not found, try clicking "Other Location" or "Computer" to search. Configure Recycle Bin properties: Right-click "Recycle Bin" and select "Properties". In the Properties window, you can adjust the following settings: Maximum Size: Limit the disk space available in the Recycle Bin. Retention time: Set the preservation before the file is automatically deleted in the recycling bin

How to restart the apache server How to restart the apache server Apr 13, 2025 pm 01:12 PM

To restart the Apache server, follow these steps: Linux/macOS: Run sudo systemctl restart apache2. Windows: Run net stop Apache2.4 and then net start Apache2.4. Run netstat -a | findstr 80 to check the server status.

How to optimize the performance of debian readdir How to optimize the performance of debian readdir Apr 13, 2025 am 08:48 AM

In Debian systems, readdir system calls are used to read directory contents. If its performance is not good, try the following optimization strategy: Simplify the number of directory files: Split large directories into multiple small directories as much as possible, reducing the number of items processed per readdir call. Enable directory content caching: build a cache mechanism, update the cache regularly or when directory content changes, and reduce frequent calls to readdir. Memory caches (such as Memcached or Redis) or local caches (such as files or databases) can be considered. Adopt efficient data structure: If you implement directory traversal by yourself, select more efficient data structures (such as hash tables instead of linear search) to store and access directory information

See all articles