Home>Article>Operation and Maintenance> How to configure Linux sshd_config

How to configure Linux sshd_config

WBOY
WBOY forward
2023-05-14 22:13:31 2002browse

[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      # 是否可以使用压缩指令?当然可以啰!


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 的长度!


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            # 登录记录的等级!嘿嘿!任何讯息!                    # 同样的,忘记了就回去参考!


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               # 上面这个在设定若要使用不需要密码登入的账号时,那么那个               # 账号的存放档案所在档名!


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 设定失效!



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



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

x11forwarding yes #x11displayoffset 10 #x11uselocalhost yes


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 ,              # 但是尚未输入密码时,这个时候就是我们所谓的联机画面啦!              # 在这个联机画面中,为了保护主机,所以需要设定最大值,              # 预设最多十个联机画面,而已经建立联机的不计算在这十个当中


4.6 Setting items about user resistance:

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


5. About the setting items of sftp service!

subsystem sftp /usr/lib/ssh/sftp-server

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:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete