<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>System Login Security (系统登录安全) &#8211; Eternal Center</title>
	<atom:link href="https://eternalcenter-sep-2022.github.io/category/system/system-network-system-security-system-log/system-security/system-login-security/feed/" rel="self" type="application/rss+xml" />
	<link>https://eternalcenter-sep-2022.github.io/</link>
	<description></description>
	<lastBuildDate>Fri, 09 Sep 2022 09:42:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>[内容] Linux 密码文件 /etc/shadow 的介绍 （显示用户密码相关的策略）</title>
		<link>https://eternalcenter-sep-2022.github.io/etc-shadow/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 09 Sep 2022 09:40:25 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Setting (系统设置)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=28282</guid>

					<description><![CDATA[内容一：/etc/shadow 文件的简介 1) /etc/shadow 文件存储着用户的密码和与之相关的信息2) /etc/shadow 文件以冒号 “:” 作为分隔符，分类 8 段 内容二：/etc/shadow 文件的作用 2.1 第 1 段内容：用户名 /etc/shadow 文件的第 1 段存储的是用户名，和 /etc/passwd 文件中的用户名是一一对应的 2.2 第 2 段内容：密码 2.2.1 内容的含义 1) 如果是奇怪的字符串则代表是加密过的密码，格式是 $id$salt$hashed，其中 $id 是指加密算法。如果字符串：以 $1$ 开头则代表是用 MD5 加密，以 $2a$ 开头则代表是用 Blowfish 加密，以 $2y$ 开头则代表是用另一种算法长度的 Blowfish 加密，以 $5$ 开头则代表是用 SHA-256 加密，以 $6$ 开头则代表是用 SHA-512 加密2) 如果是 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/etc-shadow/" class="more-link">Continue reading<span class="screen-reader-text"> "[内容] Linux 密码文件 /etc/shadow 的介绍 （显示用户密码相关的策略）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3>内容一：/etc/shadow 文件的简介</h3>



<p>1) /etc/shadow 文件存储着用户的密码和与之相关的信息<br>2) /etc/shadow 文件以冒号 “:” 作为分隔符，分类 8 段</p>



<h3>内容二：/etc/shadow 文件的作用</h3>



<h4>2.1 第 1 段内容：用户名</h4>



<p>/etc/shadow 文件的第 1 段存储的是用户名，和 /etc/passwd 文件中的用户名是一一对应的</p>



<h4>2.2 第 2 段内容：密码</h4>



<h5>2.2.1 内容的含义</h5>



<p>1) 如果是奇怪的字符串则代表是加密过的密码，格式是 $id$salt$hashed，其中 $id 是指加密算法。如果字符串：以 $1$ 开头则代表是用 MD5 加密，以 $2a$ 开头则代表是用 Blowfish 加密，以 $2y$ 开头则代表是用另一种算法长度的 Blowfish 加密，以 $5$ 开头则代表是用 SHA-256 加密，以 $6$ 开头则代表是用 SHA-512 加密<br>2) 如果是 2 个感叹号 “!!” 则代表从来都没有设置过密码<br>3) 如果为空则代表没有设置密码<br>4) 如果是 1 个星号 “*” 则代表用户被锁定，但是其它登陆方式不受限制，例 SSH 登陆<br>5) 如果是 1 个感叹号 “!” 则代表用户被锁定，但是其它登陆方式不受限制，例 SSH 登陆<br>6) 如果以 1 个感叹号开头 “!” 则代表用户被锁定<br>7) 如果以 2 个感叹号开头 “!!” 则代表用户被锁定</p>



<h5>2.2.2 查看命令</h5>



<pre class="wp-block-code"><code># cut -d: -f1,7</code></pre>



<h5>2.2.3 修改命令</h5>



<pre class="wp-block-code"><code># passwd &lt;user&gt;</code></pre>



<h4>2.3 第 3 段内容：密码最后的修改日期</h4>



<h5>2.3.1 内容的含义</h5>



<p>密码最后修改的日期于 1970 年 1 月 1 日相距的天数</p>



<h5>2.3.2 查看命令</h5>



<pre class="wp-block-code"><code># egrep ^&#91;^:]+:&#91;^\!*] /etc/shadow | cut -d: -f1,3</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage -l &lt;user&gt; | grep 'Last password change'</code></pre>



<h5>2.3.3 修改命令</h5>



<pre class="wp-block-code"><code># chage -d &lt;date&gt; &lt;user&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage --lastday &lt;date&gt; &lt;user&gt;</code></pre>



<h4>2.4 第 4 段内容：修改密码最短天数间隔</h4>



<h5>2.4.1 内容的含义</h5>



<p>两次修改密码最短天数间隔</p>



<p>1) 如果是 0 则代表随时可以修改密码<br>2) 如果是 99999 则代表永远都不能修改密码</p>



<h5>2.4.2 查看命令</h5>



<pre class="wp-block-code"><code># egrep ^&#91;^:]+:&#91;^\!*] /etc/shadow | cut -d: -f1,4</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage -l &lt;user&gt; | grep 'Minimum number of days between password change'</code></pre>



<h5>2.4.3 修改命令</h5>



<pre class="wp-block-code"><code># chage -m &lt;days&gt; &lt;user&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage --mindays &lt;days&gt; &lt;user&gt;</code></pre>



<h4>2.5 第 5 段内容：密码过期的天数</h4>



<h5>2.5.1 内容的含义</h5>



<p>修改密码后过多少天会过期</p>



<p>1) 如果是 99999 则代表永远都不会过期<br>2) 如果密码只是过期但是没有失效的话，则可以使用过期的密码更改密码再使用新密码登陆，如果密码失效的话则此密码不能再使用</p>



<h5>2.5.2 查看命令</h5>



<pre class="wp-block-code"><code># egrep ^&#91;^:]+:&#91;^\!*] /etc/shadow | cut -d: -f1,5</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage -l &lt;user&gt; | grep 'Maximum number of days between password change'</code></pre>



<h5>2.5.3 修改命令</h5>



<pre class="wp-block-code"><code># chage -M &lt;days&gt; &lt;user&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage --maxdays &lt;days&gt; &lt;user&gt;</code></pre>



<h4>2.6 第 6 段内容：密码过期前提前多少天发出警告</h4>



<h5>2.6.1 内容的含义</h5>



<p>密码过期前，提前多少天发出警告</p>



<p>如果为空则代表不发出警告</p>



<h5>2.6.2 查看命令</h5>



<pre class="wp-block-code"><code># egrep ^&#91;^:]+:&#91;^\!*] /etc/shadow | cut -d: -f1,6</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage -l &lt;user&gt; | grep 'Number of days of warning before password expires'</code></pre>



<h5>2.6.3 修改密码</h5>



<pre class="wp-block-code"><code># chage -W &lt;days&gt; &lt;user&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage --warndays &lt;days&gt; &lt;user&gt;</code></pre>



<h4>2.7 第 7 段内容：密码失效的天数</h4>



<h5>2.7.1 内容的含义</h5>



<p>密码过期后过多少天会失效</p>



<p>1) 如果是 99999 则代表永远都不会失效<br>2) 如果密码只是过期但是没有失效的话，则可以使用过期的密码更改密码再使用新密码登陆，如果密码失效的话则此密码不能再使用</p>



<h5>2.7.2 查看命令</h5>



<pre class="wp-block-code"><code># egrep ^&#91;^:]+:&#91;^\!*] /etc/shadow | cut -d: -f1,7</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage -l &lt;user&gt; | grep 'Password inactive'</code></pre>



<h5>2.7.3 修改密码</h5>



<pre class="wp-block-code"><code># chage -I &lt;days&gt; &lt;user&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage --inactive &lt;days&gt; &lt;user&gt;</code></pre>



<h4>2.8 第 8 段内容：用户的失效日期</h4>



<h5>2.8.1 内容的含义</h5>



<p>用户的失效日期于 1970 年 1 月 1 日相距的天数</p>



<h5>2.8.2 查看命令</h5>



<pre class="wp-block-code"><code># egrep ^&#91;^:]+:&#91;^\!*] /etc/shadow | cut -d: -f1,8</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage -l &lt;user&gt; | grep 'Account expires'</code></pre>



<h5>2.8.3 修改密码</h5>



<pre class="wp-block-code"><code># chage -E &lt;date&gt; &lt;user&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># chage --expiredate &lt;date&gt; &lt;user&gt;</code></pre>



<h4>2.9 第 9 段内容：保留</h4>



<p>这是一个保留位，目前没有作用</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] Linux SSH 加密算法的设置 (不使用来自 crypto policies 的系统全局 SSH 加密算法) (RHEL 8 版)</title>
		<link>https://eternalcenter-sep-2022.github.io/ssh-encryption-algorithm-no-crypto-policies-rhel-8/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 29 Aug 2022 07:06:59 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=27933</guid>

					<description><![CDATA[注意： RHEL 8 的 SSH 加密算法默认会使用来自 crypto policies 系统的全局 SSH 加密算法，而此方法将让 SSH 使用单独设置的 SSH 加密算法。 正文： 步骤一：启用 SSH 加密算法 1.1 备份 /etc/sysconfig/sshd 配置文件 1.2 修改 /etc/sysconfig/sshd 配置文件 将以下内容： 修改为： 步骤二：设置 SSH 的加密算法 2.1 在 /etc/crypto-policies/back-ends/opensshserver.config 配置文件中确认要使用的 SSH 加密算法属性 2.1.1 修改 /etc/crypto-policies/back-ends/opensshserver.config 配置文件 添加需要使用的 SSH 加密算法属性： （内容略） （注意：如果需要使用的 SSH 加密算法已包含在其中了则可以不用添加） 2.1.2 显示目前正在被使用的 SSH 加密算法 （补充：这里以显示 RHEL8 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/ssh-encryption-algorithm-no-crypto-policies-rhel-8/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] Linux SSH 加密算法的设置 (不使用来自 crypto policies 的系统全局 SSH 加密算法) (RHEL 8 版)"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>注意：</h2>



<p>RHEL 8 的 SSH 加密算法默认会使用来自 crypto policies 系统的全局 SSH 加密算法，而此方法将让 SSH 使用单独设置的 SSH 加密算法。</p>



<h2>正文：</h2>



<h3>步骤一：启用 SSH 加密算法</h3>



<h4>1.1 备份 /etc/sysconfig/sshd 配置文件</h4>



<pre class="wp-block-code"><code># cp /etc/sysconfig/sshd /etc/sysconfig/sshd_backup</code></pre>



<h4>1.2 修改 /etc/sysconfig/sshd 配置文件</h4>



<pre class="wp-block-code"><code># vim /etc/sysconfig/sshd</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code># CRYPTO_POLICY=</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>CRYPTO_POLICY=</code></pre>



<h3>步骤二：设置 SSH 的加密算法</h3>



<h4>2.1 在 /etc/crypto-policies/back-ends/opensshserver.config 配置文件中确认要使用的 SSH 加密算法属性</h4>



<h5>2.1.1 修改 /etc/crypto-policies/back-ends/opensshserver.config 配置文件</h5>



<pre class="wp-block-code"><code># vim /etc/crypto-policies/back-ends/opensshserver.config</code></pre>



<p>添加需要使用的 SSH 加密算法属性：</p>



<p>（内容略）</p>



<p>（注意：如果需要使用的 SSH 加密算法已包含在其中了则可以不用添加）</p>



<h5>2.1.2 显示目前正在被使用的 SSH 加密算法</h5>



<pre class="wp-block-code"><code># printf "%s\n" $(source /etc/crypto-policies/back-ends/opensshserver.config; echo $CRYPTO_POLICY) | cut -c3-
Ciphers=aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes256-cbc,aes128-gcm@openssh.com,aes128-ctr,aes128-cbc
MACs=hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha1,umac-128@openssh.com,hmac-sha2-512
GSSAPIKexAlgorithms=gss-curve25519-sha256-,gss-nistp256-sha256-,gss-group14-sha256-,gss-group16-sha512-,gss-gex-sha1-,gss-group14-sha1-
KexAlgorithms=curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
HostKeyAlgorithms=ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com,ssh-rsa,ssh-rsa-cert-v01@openssh.com
PubkeyAcceptedKeyTypes=ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com,ssh-rsa,ssh-rsa-cert-v01@openssh.com
CASignatureAlgorithms=ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,rsa-sha2-256,rsa-sha2-512,ssh-rsa</code></pre>



<p>（补充：这里以显示 RHEL8 默认使用的 SSH 加密算法为例）</p>



<h4>2.2 在 /etc/ssh/sshd_config 配置文件中设置要使用的 SSH 加密算法</h4>



<h5>2.2.1 备份 /etc/ssh/sshd_config 配置文件</h5>



<pre class="wp-block-code"><code># cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup</code></pre>



<h5>2.2.2 在 /etc/ssh/sshd_config 配置文件中添加要使用的 SSH 加密算法</h5>



<pre class="wp-block-code"><code># vim /etc/ssh/sshd_config</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
Ciphers aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512,hmac-sha2-256
KexAlgorithms ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256</code></pre>



<p>（<br>补充：这里以使用：<br>1) aes256-ctr、aes192-ctr 和 aes128-ctr SSH Ciphers 加密算法<br>2) hmac-sha2-512 和 hmac-sha2-256 SSH MACs 加密算法<br>3) ecdh-sha2-nistp521、ecdh-sha2-nistp384、ecdh-sha2-nistp256 和 diffie-hellman-group-exchange-sha256 SSH KexAlgorithms 加密算法<br>为例<br>）</p>



<h5>2.2.3 让在 /etc/ssh/sshd_config 配置文件中添加要使用的 SSH 加密算法生效</h5>



<pre class="wp-block-code"><code># systemctl restart sshd</code></pre>



<h3>步骤三：测试 SSH 加密算法</h3>



<h4>3.1 测试 SSH Ciphers 加密算法</h4>



<h5>3.1.1 测试某个 SSH Ciphers 加密算法</h5>



<pre class="wp-block-code"><code># ssh -vv -oCiphers=3des-cbc -oPort=22 192.168.0.1</code></pre>



<p>（补充：这里以测试 IP 地址是 192.168.0.1，端口号是 22，有没有启用 3des-cbc SSH Ciphers 加密算法为例）</p>



<h5>3.1.2 测试多个 SSH Ciphers 加密算法</h5>



<pre class="wp-block-code"><code># ssh -vv -oCiphers=3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc -oPort=22 192.168.0.1</code></pre>



<p>（补充：这里以测试 IP 地址是 192.168.0.1，端口号是 22，有没有启用 3des-cbc、aes128-cbc、aes192-cbc 和 aes256-cbc SSH Ciphers 加密算法为例）</p>



<h4>3.2 测试 SSH MACs 加密算法</h4>



<h5>3.2.1 测试某个 SSH Ciphers 加密算法</h5>



<pre class="wp-block-code"><code># ssh -vv -oMACs=hmac-md5 -oPort=22 192.168.0.1</code></pre>



<p>（补充：这里以测试 IP 地址是 192.168.0.1，端口号是 22，有没有启用 hmac-md5 SSH MACs 加密算法为例）</p>



<h5>3.2.2 测试多个 SSH Ciphers 加密算法</h5>



<pre class="wp-block-code"><code># ssh -vv -oMACs=hmac-md5,hmac-md5-96,hmac-sha1,hmac-sha1-96,hmac-md5-etm@openssh.com,hmac-md5-96-etm@openssh.com -oPort=22 192.168.0.1</code></pre>



<p>（补充：这里以测试 IP 地址是 192.168.0.1，端口号是 22，有没有启用 hmac-md5、hmac-md5-96、hmac-sha1、hmac-sha1-96、hmac-md5-etm@openssh.com 和 hmac-md5-96-etm@openssh.com SSH MACs 加密算法为例）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] nftables 防火墙策略文件的常用规则</title>
		<link>https://eternalcenter-sep-2022.github.io/common-rules-for-nftables-firewall-policy-file/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 15 Aug 2022 03:31:10 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Firewall (系统防火墙)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=27551</guid>

					<description><![CDATA[注意： 在给 nftables 防火墙的策略文件添加规则前，要先使用 nftables 防火墙的策略文件： 正文： 案例一：允许某个 IP 地址访问某个端口 或者： （补充：这里以允许 IP 地址 192.168.0.1 访问 22 端口为例） 案例二：允许某个 IP 地址访问多个端口 （补充：这里以允许 IP 地址 192.168.0.1 访问 22 端口、80 端口、443 端口和 3066 端口为例） 案例三：允许多个 IP 地址访问多个端口 （补充：这里以允许 IP 地址 192.168.0.1、192.168.0.2 和 192.168.0.3 访问 22 端口、80 端口、443 端口和 3066 端口为例） 案例四：拒绝所有 IP 地址访问多个端口 （补充：这里以拒绝所有 IP 地址的 22 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/common-rules-for-nftables-firewall-policy-file/" class="more-link">Continue reading<span class="screen-reader-text"> "[内容] nftables 防火墙策略文件的常用规则"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>注意：</h2>



<p>在给 nftables 防火墙的策略文件添加规则前，要先使用 nftables 防火墙的策略文件：</p>



<div class="wp-container-1 is-content-justification-center wp-block-buttons">
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link" href="https://eternalcenter-sep-2022.github.io/nfttables-permanent/" style="border-radius:0px">nftables 防火墙的使用 <br>（永久版）</a></div>
</div>



<h2>正文：</h2>



<h3>案例一：允许某个 IP 地址访问某个端口</h3>



<pre class="wp-block-code"><code>ip saddr 192.168.0.1 tcp dport ssh accept</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>ip saddr 192.168.0.1 tcp dport 22 accept</code></pre>



<p>（补充：这里以允许 IP 地址 192.168.0.1 访问 22 端口为例）</p>



<h3>案例二：允许某个 IP 地址访问多个端口</h3>



<pre class="wp-block-code"><code>ip saddr 192.168.0.1 tcp dport {22,80,443,3306} accept comment "accept local port"</code></pre>



<p>（补充：这里以允许 IP 地址 192.168.0.1 访问 22 端口、80 端口、443 端口和 3066 端口为例）</p>



<h3>案例三：允许多个 IP 地址访问多个端口</h3>



<pre class="wp-block-code"><code>ip saddr {192.168.0.1,192.168.0.2,192.168.0.3} tcp dport {22,80,443,3306} accept comment "accept local port"</code></pre>



<p>（补充：这里以允许 IP 地址 192.168.0.1、192.168.0.2 和 192.168.0.3 访问 22 端口、80 端口、443 端口和 3066 端口为例）</p>



<h3>案例四：拒绝所有 IP 地址访问多个端口</h3>



<pre class="wp-block-code"><code>tcp dport {22,80,443,3306} drop comment "drop remote port"</code></pre>



<p>（补充：这里以拒绝所有 IP 地址的 22 端口、80 端口、443 端口和 3306 端口为例）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 gpasswd （管理组）</title>
		<link>https://eternalcenter-sep-2022.github.io/gpasswd/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 29 Jul 2022 07:38:45 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Privilege (系统权限)]]></category>
		<category><![CDATA[System Privilege Security (系统权限安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System User (系统用户)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=27450</guid>

					<description><![CDATA[内容一：组的成员管理 1.1 把用户添加到组里 1.1.1 把某个用户添加到某个组 或者： 或者： 或者： 1.1.2 把多个用户添加到某个组 或者： 或者： 或者： 2.2 把用户从组里删除 2.2.1 把某个用户从某个组里删除 或者： 2.2.2 把多个用户添加到某个组 或者： 2.3 将某个用户设置为组的管理员 或者： 内容三：组的密码管理 3.1 给某个组设置密码 3.2 删除某个组的密码 或者： 内容四：组的登录管理 限制某个组登录 或者： 内容五：显示帮助信息 或者：]]></description>
										<content:encoded><![CDATA[
<h3>内容一：组的成员管理</h3>



<h4>1.1 把用户添加到组里</h4>



<h5>1.1.1 把某个用户添加到某个组</h5>



<pre class="wp-block-code"><code># gpasswd -a &lt;user&gt; &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd –add &lt;user&gt; &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd -M &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd –members &lt;group&gt;</code></pre>



<h5>1.1.2 把多个用户添加到某个组</h5>



<pre class="wp-block-code"><code># gpasswd -a &lt;user1&gt;,&lt;user2&gt; &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd –add &lt;user1&gt;,&lt;user2&gt; &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd -M &lt;user1&gt;,&lt;user2&gt; &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd –members &lt;user1&gt;,&lt;user2&gt; &lt;group&gt;</code></pre>



<h4>2.2 把用户从组里删除</h4>



<h5>2.2.1 把某个用户从某个组里删除</h5>



<pre class="wp-block-code"><code># gpasswd -d &lt;user&gt; &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd –delete &lt;user&gt; &lt;group&gt;</code></pre>



<h5>2.2.2 把多个用户添加到某个组</h5>



<pre class="wp-block-code"><code># gpasswd -d &lt;user1&gt;,&lt;user2&gt; &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd –delete &lt;user1&gt;,&lt;user2&gt; &lt;group&gt;</code></pre>



<h4>2.3 将某个用户设置为组的管理员</h4>



<pre class="wp-block-code"><code># gpasswd -A &lt;user&gt; &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd –administrators &lt;user&gt; &lt;group&gt;</code></pre>



<h3>内容三：组的密码管理</h3>



<h4>3.1 给某个组设置密码</h4>



<pre class="wp-block-code"><code># gpasswd &lt;group&gt;</code></pre>



<h4>3.2 删除某个组的密码</h4>



<pre class="wp-block-code"><code># gpasswd –r &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd –remove-password &lt;group&gt;</code></pre>



<h3>内容四：组的登录管理</h3>



<p>限制某个组登录</p>



<pre class="wp-block-code"><code># gpasswd -R &lt;group&gt;</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd –restrict &lt;group&gt;</code></pre>



<h3>内容五：显示帮助信息</h3>



<pre class="wp-block-code"><code># gpasswd -h</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># gpasswd -help</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux 文件 profile 和 bashrc （用户登录环境的设置）</title>
		<link>https://eternalcenter-sep-2022.github.io/profile-bashrc/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 29 Jul 2022 06:43:12 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Privilege (系统权限)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Setting (系统设置)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<category><![CDATA[System User (系统用户)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=27441</guid>

					<description><![CDATA[内容一：profile 文件 1.1 profile 全局文件的位置 （影响所有用户） 1.2 profile 局部文件的位置 （只影响单个用户） 或者： 或者： 1.3 profile 文件的作用 在用户登录时设置用户的环境变量，只在用户登录时才会生效 1.4 登录 Linux 时执行 profile 文件的顺序 第一步，执行： 第二步，按以下顺序一一尝试执行以下 3 个文件中的 1 个，当执行成功后则停止尝试下 1 个文件： 第三步：开始调用解释器 （如果是调用 bash 解释器，则继续执行登录 bash 时执行 bashrc 文件的顺序） 内容二：bashrc 文件 2.1 bashrc 全局文件的位置 （影响所有用户） 或者： 2.2 bashrc 局部文件的位置 （只影响单个用户） 2.3 bashrc 文件的作用 在用户使用 bash 解释器或登录 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/profile-bashrc/" class="more-link">Continue reading<span class="screen-reader-text"> "[内容] Linux 文件 profile 和 bashrc （用户登录环境的设置）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3>内容一：profile 文件</h3>



<h4>1.1 profile 全局文件的位置 （影响所有用户）</h4>



<pre class="wp-block-code"><code>/etc/profile</code></pre>



<h4>1.2 profile 局部文件的位置 （只影响单个用户）</h4>



<pre class="wp-block-code"><code>~/.bash_profile</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>~/.bash_login</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>~/.profile</code></pre>



<h4>1.3 profile 文件的作用</h4>



<p>在用户登录时设置用户的环境变量，只在用户登录时才会生效</p>



<h4>1.4 登录 Linux 时执行 profile 文件的顺序</h4>



<p>第一步，执行：</p>



<pre class="wp-block-code"><code>/etc/profile</code></pre>



<p>第二步，按以下顺序一一尝试执行以下 3 个文件中的 1 个，当执行成功后则停止尝试下 1 个文件：</p>



<pre class="wp-block-code"><code>~/.bash_profile
~/.bash_login
~/.profile</code></pre>



<p>第三步：开始调用解释器</p>



<p>（如果是调用 bash 解释器，则继续执行登录 bash 时执行 bashrc 文件的顺序）</p>



<h3>内容二：bashrc 文件</h3>



<h4>2.1 bashrc 全局文件的位置 （影响所有用户）</h4>



<pre class="wp-block-code"><code>/etc/bashrc</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>/etc/bash.bashrc</code></pre>



<h4>2.2 bashrc 局部文件的位置 （只影响单个用户）</h4>



<pre class="wp-block-code"><code>~/.bashrc</code></pre>



<h4>2.3 bashrc 文件的作用</h4>



<p>在用户使用 bash 解释器或登录 bash 解释器时设置用户的环境变量，每次调用 bash 解释器时都会生效</p>



<h4>2.4 使用 bash 或登录 bash 时执行 bashrc 文件的顺序</h4>



<p>第一步，执行以下 2 个文件中的 1 个：</p>



<pre class="wp-block-code"><code>/etc/bashrc
/etc/bash.bashrc</code></pre>



<p>第二步，执行：</p>



<pre class="wp-block-code"><code>~/.bashrc</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Linux 防范黑客入侵的思路</title>
		<link>https://eternalcenter-sep-2022.github.io/thoughts-on-preventing-hacker-intrusion-in-linux/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 28 Jul 2022 08:33:56 +0000</pubDate>
				<category><![CDATA[Articles (文章)]]></category>
		<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Creations (创作)]]></category>
		<category><![CDATA[Information Technology (IT) Articles (信息技术类文章)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System and System Software's Update and Patch (系统和系统软件的更新和补丁)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Firewall (系统防火墙)]]></category>
		<category><![CDATA[System Log (系统日志)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Privilege Security (系统权限安全)]]></category>
		<category><![CDATA[System Process Security (系统进程安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Security Log (系统安全日志)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=27358</guid>

					<description><![CDATA[黑客发现阶段 黑客在入侵前往往会先对整个网络进行扫描，尝试发现我们的系统。在这个阶段我们可以尝试的防范措施有： 1) 关闭 ICMP 协议，让黑客无法通过 ping 发现我们的系统2) 关闭所有不需要的端口3) 通过防火墙只让允许访问的 IP 地址访问对应的端口4) 让防火墙使用 drop 操作丢掉所有没有被允许的访问请求 黑客列举阶段和黑客立足阶段 黑客在发现了我们的系统之后。会根据我们系统和软件的版本，列举不同的破解方法并进行取舍，并最终会选择一种或多种方法进行尝试。在这两个阶段我们可以尝试的防范措施有： 1) 不使用盗版的系统和软件2) 不使用有漏洞的系统和软件3) 尽量将所有的系统和软件升级到最新的版本4) 删除所有非必须的软件5) 在用户尝试登录系统时，取消显示系统的版本6) 删除或禁用所有不需要的用户7) 让所有的用户都使用复杂的密码8) 定期检查和修改所有用户的密码9) 定期检查和修改所有用户 ~/.ssh/ 目录中的密钥10) 限制错误密码尝试的次数，以防止暴力破解11) 定期检查系统防火墙策略12) 定期检查系统开启的所有端口13) 定期检查系统开启的所有进程14) 定期查看 /var/log/message 中的尝试登录失败的日志记录 黑客保持持久性阶段 黑客在成功进入系统以后，会尝试为自己下次进入系统准备方法，以让入侵保持持久性。在这个阶段我们可以尝试的防范措施有： 1) 定期检查系统中的所有用户的名称和数量2) 定期检查系统中所有拥有 root 权限的名称和数量3) 定期检查和修改所有用户的密码4) 定期检查和修改所有用户 ~/.ssh/ 目录中的密钥5) 定期检查系统防火墙策略6) 定期检查系统开启的所有端口7) 定期检查系统开启的所有进程8) 缩小重要文件的权限9) 定期检查所有用户的登录日志10) 通过 auditd 服务监控所有重要配置文件，并定期检查监控日志 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/thoughts-on-preventing-hacker-intrusion-in-linux/" class="more-link">Continue reading<span class="screen-reader-text"> "Linux 防范黑客入侵的思路"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3>黑客发现阶段</h3>



<p>黑客在入侵前往往会先对整个网络进行扫描，尝试发现我们的系统。在这个阶段我们可以尝试的防范措施有：</p>



<p>1) 关闭 ICMP 协议，让黑客无法通过 ping 发现我们的系统<br>2) 关闭所有不需要的端口<br>3) 通过防火墙只让允许访问的 IP 地址访问对应的端口<br>4) 让防火墙使用 drop 操作丢掉所有没有被允许的访问请求</p>



<h3>黑客列举阶段和黑客立足阶段</h3>



<p>黑客在发现了我们的系统之后。会根据我们系统和软件的版本，列举不同的破解方法并进行取舍，并最终会选择一种或多种方法进行尝试。在这两个阶段我们可以尝试的防范措施有：</p>



<p>1) 不使用盗版的系统和软件<br>2) 不使用有漏洞的系统和软件<br>3) 尽量将所有的系统和软件升级到最新的版本<br>4) 删除所有非必须的软件<br>5) 在用户尝试登录系统时，取消显示系统的版本<br>6) 删除或禁用所有不需要的用户<br>7) 让所有的用户都使用复杂的密码<br>8) 定期检查和修改所有用户的密码<br>9) 定期检查和修改所有用户 ~/.ssh/ 目录中的密钥<br>10) 限制错误密码尝试的次数，以防止暴力破解<br>11) 定期检查系统防火墙策略<br>12) 定期检查系统开启的所有端口<br>13) 定期检查系统开启的所有进程<br>14) 定期查看 /var/log/message 中的尝试登录失败的日志记录</p>



<h3>黑客保持持久性阶段</h3>



<p>黑客在成功进入系统以后，会尝试为自己下次进入系统准备方法，以让入侵保持持久性。在这个阶段我们可以尝试的防范措施有：</p>



<p>1) 定期检查系统中的所有用户的名称和数量<br>2) 定期检查系统中所有拥有 root 权限的名称和数量<br>3) 定期检查和修改所有用户的密码<br>4) 定期检查和修改所有用户 ~/.ssh/ 目录中的密钥<br>5) 定期检查系统防火墙策略<br>6) 定期检查系统开启的所有端口<br>7) 定期检查系统开启的所有进程<br>8) 缩小重要文件的权限<br>9) 定期检查所有用户的登录日志<br>10) 通过 auditd 服务监控所有重要配置文件，并定期检查监控日志</p>



<h3>黑客掩盖痕迹阶段</h3>



<p>黑客让入侵保持持久性后，会尝试掩盖自己的痕迹。在这个阶段我们可以尝试的防范措施有：</p>



<p>1) 定期检查系统中的所有用户的名称和数量<br>2) 定期检查系统中所有拥有 root 权限的名称和数量<br>3) 定期检查和修改所有用户的密码<br>4) 定期检查和修改所有用户 ~/.ssh/ 目录中的密钥<br>5) 定期检查系统防火墙策略<br>6) 定期检查系统开启的所有端口<br>7) 定期检查系统开启的所有进程<br>8) 缩小重要文件的权限<br>9) 定期检查所有用户的登录日志，注意日志的时间是否连贯<br>10) 通过 auditd 服务监控所有重要配置文件，并定期检查监控日志，注意日志的时间是否连贯</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] Linux 密码的安全 （本地和 SSH 输错密码次数的限制） （pam_tally2.so 版） （CentOS Linux 7 &#038; RHEL 7 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/password-security-local-ssh-login-attempt-pam_tally2-so-centos-linux-rhe-7l/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 16 Jul 2022 17:27:59 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=26943</guid>

					<description><![CDATA[正文： 步骤一：让 sshd 使用可插入身份验证模块 1.1 修改 sshd 的配置文件 将以下内容： 修改为： 1.2 让修改的 sshd 配置文件生效 步骤二：让本地登录和 sshd 登录使用密码认证 2.1 确认 /etc/pam.d/login 配置文件 确保包含以下内容： 2.2 确认 /etc/pam.d/sshd 配置文件 确保包含以下内容： 步骤三：在 /etc/pam.d/system-auth-ac 配置文件中添加 pam_tally2.so 模块和相关参数 添加以下内容： （补充：1) 这里的 pam_tally2.so 代表使用 pam_tally2.so 模块2) 这里的 silent 代表不会显示信息性的消息3) 这里的 deny=15 代表输错 15 次后会禁止登录4) 这里的 unlock_time=3000 代表禁止登录后 3000 毫秒后可以重新登录5) 这里的 even_deny_root 代表 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/password-security-local-ssh-login-attempt-pam_tally2-so-centos-linux-rhe-7l/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] Linux 密码的安全 （本地和 SSH 输错密码次数的限制） （pam_tally2.so 版） （CentOS Linux 7 &#038; RHEL 7 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>正文：</h2>



<h3>步骤一：让 sshd 使用可插入身份验证模块</h3>



<h4>1.1 修改 sshd 的配置文件</h4>



<pre class="wp-block-code"><code># vim /etc/ssh/sshd_config</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
#UsePAM no
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
UsePAM yes
......</code></pre>



<h4>1.2 让修改的 sshd 配置文件生效</h4>



<pre class="wp-block-code"><code># systemctl restart sshd</code></pre>



<h3>步骤二：让本地登录和 sshd 登录使用密码认证</h3>



<h4>2.1 确认 /etc/pam.d/login 配置文件</h4>



<pre class="wp-block-code"><code># cat /etc/pam.d/login | grep system-auth</code></pre>



<p>确保包含以下内容：</p>



<pre class="wp-block-code"><code>auth       substack     system-auth
account    include      system-auth
password   include      system-auth
session    include      system-auth</code></pre>



<h4>2.2 确认 /etc/pam.d/sshd 配置文件</h4>



<pre class="wp-block-code"><code># cat /etc/pam.d/sshd | grep password-auth</code></pre>



<p>确保包含以下内容：</p>



<pre class="wp-block-code"><code>auth       substack     password-auth
account    include      password-auth
password   include      password-auth
session    include      password-auth</code></pre>



<h3>步骤三：在 /etc/pam.d/system-auth-ac 配置文件中添加 pam_tally2.so 模块和相关参数</h3>



<pre class="wp-block-code"><code># vim /etc/pam.d/system-auth-ac</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
auth required pam_tally2.so onerr=fail audit silent deny=15 unlock_time=3000 even_deny_root root_unlock_time=3000</code></pre>



<p>（<br>补充：<br>1) 这里的 pam_tally2.so 代表使用 pam_tally2.so 模块<br>2) 这里的 silent 代表不会显示信息性的消息<br>3) 这里的 deny=15 代表输错 15 次后会禁止登录<br>4) 这里的 unlock_time=3000 代表禁止登录后 3000 毫秒后可以重新登录<br>5) 这里的 even_deny_root 代表 root 用户和其它用户一样会被锁住<br>6) 这里的 root_unlock_time=3000 代表禁止 root 用户登录后 3000 毫秒后可以重新登录<br>）</p>



<h3>步骤四：在 /etc/pam.d/password-auth-ac 配置文件中添加 pam_tally2.so 模块和相关参数</h3>



<pre class="wp-block-code"><code># vim /etc/pam.d/password-auth-ac</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
auth required pam_tally2.so onerr=fail audit silent deny=15 unlock_time=3000 even_deny_root root_unlock_time=3000</code></pre>



<p>（<br>补充：<br>1) 这里的 pam_tally2.so 代表使用 pam_tally2.so 模块<br>2) 这里的 silent 代表不会显示信息性的消息<br>3) 这里的 deny=15 代表输错 15 次后会禁止登录<br>4) 这里的 unlock_time=3000 代表禁止登录后 3000 毫秒后可以重新登录<br>5) 这里的 even_deny_root 代表 root 用户和其它用户一样会被锁住<br>6) 这里的 root_unlock_time=3000 代表禁止 root 用户登录后 3000 毫秒后可以重新登录<br>）</p>



<h3>步骤五：部分用户输错密码次数限制的排除</h3>



<h4>5.1 在 /etc/pam.d/system-auth-ac 配置文件中添加 pam_succeed_if.so 模块和相关参数</h4>



<pre class="wp-block-code"><code># vim /etc/pam.d/system-auth-ac</code></pre>



<p>在此行：</p>



<pre class="wp-block-code"><code>......
auth required pam_tally2.so onerr=fail audit silent deny=15 unlock_time=3000 even_deny_root root_unlock_time=3000</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>......
auth &#91;success=1 default=ignore] pam_succeed_if.so user in mingyuzhu1:mingyuzhu2:mingyuzhu3</code></pre>



<p>（补充：这里以排除用户 zhumingyu1、zhumingyu2 和 zhumingyu3 的输错密码次数限制为例）</p>



<h4>5.2 在 /etc/pam.d/password-auth-ac 配置文件中添加 pam_succeed_if.so 模块和相关参数</h4>



<pre class="wp-block-code"><code># vim /etc/pam.d/password-auth-ac</code></pre>



<p>在此行：</p>



<pre class="wp-block-code"><code>......
auth required pam_tally2.so onerr=fail audit silent deny=15 unlock_time=3000 even_deny_root root_unlock_time=3000</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>......
auth &#91;success=1 default=ignore] pam_succeed_if.so user in mingyuzhu1:mingyuzhu2:mingyuzhu3</code></pre>



<p>（补充：这里以排除用户 zhumingyu1、zhumingyu2 和 zhumingyu3 的输错密码次数限制为例）</p>



<h2>参考文献：</h2>



<p class="has-text-align-center">https://access.redhat.com/solutions/62949</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] Linux 非 root 用户 ping 命令使用的禁止和允许</title>
		<link>https://eternalcenter-sep-2022.github.io/non-root-user-ping-diable-enable/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 15 Jul 2022 07:00:36 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network (系统网络)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Setting (系统设置)]]></category>
		<category><![CDATA[System User (系统用户)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=26794</guid>

					<description><![CDATA[步骤一：禁止非 root 用户使用 ping 步骤二：允许非 root 用户使用 ping 补充：当禁止禁止非 root 用户使用 ping 时，非 root 用户使用 ping 命令的报错 如果是 Rocky Linux &#38; RHEL： 如果是 openSUSE &#38; SLE：]]></description>
										<content:encoded><![CDATA[
<h3>步骤一：禁止非 root 用户使用 ping</h3>



<pre class="wp-block-code"><code>#  sysctl net.ipv4.ping_group_range="1 0"</code></pre>



<h3>步骤二：允许非 root 用户使用 ping</h3>



<pre class="wp-block-code"><code># sysctl net.ipv4.ping_group_range="0 2147483647"</code></pre>



<h3>补充：当禁止禁止非 root 用户使用 ping 时，非 root 用户使用 ping 命令的报错</h3>



<p>如果是 Rocky Linux &amp; RHEL：</p>



<pre class="wp-block-code"><code>ping: socket: Address family not supported by protocol</code></pre>



<p>如果是 openSUSE &amp; SLE：</p>



<pre class="wp-block-code"><code>Error: ping: socket: Operation not permitted</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] Linux 密码的安全 （本地和 SSH 输错密码次数的限制） （pam_tally2.so 版） （openSUSE &#038; SLE 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/password-security-local-ssh-login-attempt-pam_tally2-so-opensuse-sle/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 14 Jul 2022 13:07:17 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=26779</guid>

					<description><![CDATA[正文： 步骤一：让 sshd 使用可插入身份验证模块 1.1 修改 sshd 的配置文件 将以下内容： 修改为： 1.2 让修改的 sshd 配置文件生效 步骤二：让本地登录和 sshd 登录使用密码认证 2.1 确认 /etc/pam.d/login 配置文件 确保包含以下内容： 2.2 确认 /etc/pam.d/sshd 配置文件 确保包含以下内容： 步骤三：在 /etc/pam.d/common-auth-pc 配置文件中添加 pam_tally2.so 模块和相关参数 添加以下内容： （补充：1) 这里的 pam_tally2.so 代表使用 pam_tally2.so 模块2) 这里的 silent 代表不会显示信息性的消息3) 这里的 deny=15 代表输错 15 次后会禁止登录4) 这里的 unlock_time=3000 代表禁止登录后 3000 毫秒后可以重新登录5) 这里的 even_deny_root 代表 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/password-security-local-ssh-login-attempt-pam_tally2-so-opensuse-sle/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] Linux 密码的安全 （本地和 SSH 输错密码次数的限制） （pam_tally2.so 版） （openSUSE &#038; SLE 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>正文：</h2>



<h3>步骤一：让 sshd 使用可插入身份验证模块</h3>



<h4>1.1 修改 sshd 的配置文件</h4>



<pre class="wp-block-code"><code># vim /etc/ssh/sshd_config</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
#UsePAM no
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
UsePAM yes
......</code></pre>



<h4>1.2 让修改的 sshd 配置文件生效</h4>



<pre class="wp-block-code"><code># systemctl restart sshd</code></pre>



<h3>步骤二：让本地登录和 sshd 登录使用密码认证</h3>



<h4>2.1 确认 /etc/pam.d/login 配置文件</h4>



<pre class="wp-block-code"><code># cat /etc/pam.d/login | grep include</code></pre>



<p>确保包含以下内容：</p>



<pre class="wp-block-code"><code>auth      include    common-auth
account   include    common-account
password  include    common-password
session   include    common-session</code></pre>



<h4>2.2 确认 /etc/pam.d/sshd 配置文件</h4>



<pre class="wp-block-code"><code># cat /etc/pam.d/sshd | grep include</code></pre>



<p>确保包含以下内容：</p>



<pre class="wp-block-code"><code>auth        include     common-auth
account     include     common-account
password    include     common-password
session     include     common-session</code></pre>



<h3>步骤三：在 /etc/pam.d/common-auth-pc 配置文件中添加 pam_tally2.so 模块和相关参数</h3>



<pre class="wp-block-code"><code># vim /etc/pam.d/common-auth-pc</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
auth required pam_tally2.so onerr=fail audit silent deny=15 unlock_time=3000 even_deny_root root_unlock_time=3000</code></pre>



<p>（<br>补充：<br>1) 这里的 pam_tally2.so 代表使用 pam_tally2.so 模块<br>2) 这里的 silent 代表不会显示信息性的消息<br>3) 这里的 deny=15 代表输错 15 次后会禁止登录<br>4) 这里的 unlock_time=3000 代表禁止登录后 3000 毫秒后可以重新登录<br>5) 这里的 even_deny_root 代表 root 用户和其它用户一样会被锁住<br>6) 这里的 root_unlock_time=3000 代表禁止 root 用户登录后 3000 毫秒后可以重新登录<br>）</p>



<h3>步骤四：在 /etc/pam.d/common-account-pc 配置文件中添加使用 pam_tally2.so 模块和相关参数</h3>



<pre class="wp-block-code"><code># vim /etc/pam.d/common-account-pc</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
account required pam_tally2.so</code></pre>



<p>（补充：这里的 pam_tally2.so 代表加载 pam_tally2.so 模块）</p>



<h3>步骤五：用户登录失败的管理</h3>



<h4>5.1 查看某个用户近期输错了几次密码</h4>



<pre class="wp-block-code"><code># pam_tally2 -u &lt;user&gt;</code></pre>



<h4>5.2 重制某个用户登录密码输错次数</h4>



<pre class="wp-block-code"><code># pam_tally2 -u &lt;user&gt; -r --reset</code></pre>



<h3>步骤六：部分用户输错密码次数限制的排除</h3>



<h4>6.1 在 /etc/pam.d/common-auth-pc 配置文件中添加 pam_succeed_if.so 模块和相关参数</h4>



<pre class="wp-block-code"><code># vim /etc/pam.d/common-auth-pc</code></pre>



<p>在此行：</p>



<pre class="wp-block-code"><code>......
auth required pam_tally2.so onerr=fail audit silent deny=15 unlock_time=3000 even_deny_root root_unlock_time=3000</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>......
auth &#91;success=1 default=ignore] pam_succeed_if.so user in mingyuzhu1:mingyuzhu2:mingyuzhu3</code></pre>



<p>（补充：这里以排除用户 zhumingyu1、zhumingyu2 和 zhumingyu3 的输错密码次数限制为例）</p>



<h4>6.2 在 /etc/pam.d/common-account-pc 配置文件中添加 pam_succeed_if.so 模块和相关参数</h4>



<pre class="wp-block-code"><code># vim /etc/pam.d/common-account-pc</code></pre>



<p>在此行：</p>



<pre class="wp-block-code"><code>......
auth required pam_tally2.so onerr=fail audit silent deny=15 unlock_time=3000 even_deny_root root_unlock_time=3000</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>......
auth &#91;success=1 default=ignore] pam_succeed_if.so user in mingyuzhu1:mingyuzhu2:mingyuzhu3</code></pre>



<p>（补充：这里以排除用户 zhumingyu1、zhumingyu2 和 zhumingyu3 的输错密码次数限制为例）</p>



<h2>参考文献：</h2>



<p class="has-text-align-center">https://access.redhat.com/solutions/62949</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux 命令安全的设置</title>
		<link>https://eternalcenter-sep-2022.github.io/command-secure/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 25 Jun 2022 13:37:57 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Privilege Security (系统权限安全)]]></category>
		<category><![CDATA[System Process Security (系统进程安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Setting (系统设置)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=26174</guid>

					<description><![CDATA[确保以下目录的所属主和所属组是 root，且其它用户没有写入权限：]]></description>
										<content:encoded><![CDATA[
<p>确保以下目录的所属主和所属组是 root，且其它用户没有写入权限：</p>



<pre class="wp-block-code"><code># ls -ld /usr/local/bin /usr/local/sbin /usr/bin/ /usr/sbin
dr-xr-xr-x. 2 root root 53248 Jun 24 15:09 /usr/bin/
drwxr-xr-x. 3 root root  4096 Jun 21  2021 /usr/local/bin
drwxr-xr-x. 2 root root     6 Jun 21  2021 /usr/local/sbin
dr-xr-xr-x. 2 root root 20480 Jun 24 15:09 /usr/sbin</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 lsof （显示进程）</title>
		<link>https://eternalcenter-sep-2022.github.io/lsof/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 23 Jun 2022 10:06:50 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Directory (系统目录)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation (系统操作)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Performance (系统性能)]]></category>
		<category><![CDATA[System Process (系统进程)]]></category>
		<category><![CDATA[System Process & System Performance (系统进程 & 系统性能)]]></category>
		<category><![CDATA[System Process Security (系统进程安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage (系统存储)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<category><![CDATA[System User (系统用户)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=26135</guid>

					<description><![CDATA[内容一：lsof 命令输出结果 内容二：lsof 命令输出结果简介 1) COMMAND 进程名2) PID （Process Id） PID 号3) USER 用户4) FD 文件描述信息（补充：cwd 代表当前目录，txt 代表 txt 文件，rtd 代表 root 目录，mem 代表内存映射文件）5) TYPE 文件类型（补充：DIR 代表当前目录，REG 代表普通文件，CHR 代表字符，a_inode 代表 Inode 文件，FIFO 代表管道或者 socket文件，netlink 代表网络，unkonwn 代表未知）6) DEVICE 设备 ID7) SIZE/OFF 进程大小8) NODE 文件的 Inode 号9) NAME 路径或链接 内容三：lsof 使用案例 3.1 案例一：显示已经被删除的文件 3.2 案例二：显示用户已打开的案例 3.2.1 显示某用户已打开的文件 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/lsof/" class="more-link">Continue reading<span class="screen-reader-text"> "[命令] Linux 命令 lsof （显示进程）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3>内容一：lsof 命令输出结果</h3>



<pre class="wp-block-code"><code># lsof | more
COMMAND     PID   TID    USER   FD      TYPE             DEVICE  SIZE/OFF       NODE NAME
systemd       1          root  cwd       DIR              251,1      4096          1 /
......</code></pre>



<h3>内容二：lsof 命令输出结果简介</h3>



<p>1) COMMAND 进程名<br>2) PID （Process Id） PID 号<br>3) USER 用户<br>4) FD 文件描述信息<br>（补充：cwd 代表当前目录，txt 代表 txt 文件，rtd 代表 root 目录，mem 代表内存映射文件）<br>5) TYPE 文件类型<br>（补充：DIR 代表当前目录，REG 代表普通文件，CHR 代表字符，a_inode 代表 Inode 文件，FIFO 代表管道或者 socket文件，netlink 代表网络，unkonwn 代表未知）<br>6) DEVICE 设备 ID<br>7) SIZE/OFF 进程大小<br>8) NODE 文件的 Inode 号<br>9) NAME 路径或链接</p>



<h3>内容三：lsof 使用案例</h3>



<h4>3.1 案例一：显示已经被删除的文件</h4>



<pre class="wp-block-code"><code># lsof | grep deleted</code></pre>



<h4>3.2 案例二：显示用户已打开的案例</h4>



<h5>3.2.1 显示某用户已打开的文件</h5>



<pre class="wp-block-code"><code># lsof -u zhumingyu mingyuzhu</code></pre>



<p>（补充：这里以显示用户 zhumingyu 和 mingyuzhu 已打开的文件为例）</p>



<h5>3.2.2 不显示某用户已打开的文件</h5>



<pre class="wp-block-code"><code># lsof -u mingyuzhu</code></pre>



<p>（补充：这里以不显示用户 mingyuzhu 已打开的文件为例）</p>



<h4>3.3 案例三：显示进程已打开的文件</h4>



<h5>3.3.1 显示某进程已打开的文件</h5>



<pre class="wp-block-code"><code># lsof -p 1024</code></pre>



<p>（补充：这里以显示 PID 号是 1024 已打开的文件为例）</p>



<h5>3.3.2 不显示某进程已打开的所有文件</h5>



<pre class="wp-block-code"><code># lsof -p ^1024</code></pre>



<p>（补充：这里以不显示 PID 号是 1024 已打开的文件为例）</p>



<h5>3.3.3 显示某几个进程已打开的文件</h5>



<pre class="wp-block-code"><code># lsof -p 1,2,3</code></pre>



<p>（补充：这里以显示 PID 号是 1、2 和 3 已打开的文件为例）</p>



<h4>3.4 案例四：显示已打开的网络文件</h4>



<h5>3.4.1 显示所有已打开的网络文件</h5>



<pre class="wp-block-code"><code># lsof -i</code></pre>



<h5>3.4.2 显示所有 IPv4 协议已打开的文件</h5>



<pre class="wp-block-code"><code># lsof -i 4</code></pre>



<h5>3.4.3 显示所有 IPv6 协议已打开的文件</h5>



<pre class="wp-block-code"><code># lsof -i 6</code></pre>



<h5>3.4.4 显示所有 TCP 协议已打开的文件</h5>



<pre class="wp-block-code"><code># lsof -i TCP</code></pre>



<h5>3.4.5 显示所有 TCP 协议已打开的文件</h5>



<pre class="wp-block-code"><code># lsof -i UDP</code></pre>



<h5>3.4.6 显示某个 TCP 端口或者 UDP 端口已打开的文件</h5>



<pre class="wp-block-code"><code># lsof -i:22</code></pre>



<p>（补充：这里以显示 TCP 或者 UPD 的 22 端口已打开的文件为例）</p>



<h5>3.4.7 显示某个 TCP 端口已打开的文件</h5>



<pre class="wp-block-code"><code># lsof -i TCP:22</code></pre>



<p>（补充：这里以显示 TCP 的 22 端口已打开的文件为例）</p>



<h5>3.4.8 显示某几个 TCP 端口打开的文件</h5>



<pre class="wp-block-code"><code># lsof -i TCP:1-1024</code></pre>



<p>（补充：这里以显示 TCP 的 1 端口到 1024 端口打开的文件为例）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] wtmp 日志保存时间默认策略的设置 （设置 last 命令可以显示多久以前记录）</title>
		<link>https://eternalcenter-sep-2022.github.io/wtmp/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 17 Jun 2022 13:15:11 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Log (系统日志)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Security Log (系统安全日志)]]></category>
		<category><![CDATA[System Setting (系统设置)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=24466</guid>

					<description><![CDATA[如果是 Rocky Linux &#38; RHEL： （补充：1) 影响的日志文件有 /var/log/wtmp （/var/log/wtmp）2) 每月将现在的日志文件进行备份并生成新的日志文件 （monthly）3) 日志文件权限是 0644 所属主是 root （create 0664 root utmp）4) 只有当日志文件超过 1 M 时，且达到备份的时间才会开始备份5) 备份的日志文件保留 5 份 （rotate 1）） 如果是 openSUSE &#38; SLE： （补充：1) 影响的日志文件有 /var/log/wtmp 和 /var/log/btmp （/var/log/wtmp /var/log/btmp）2) 对备份的日志文件进行压缩 （compress）3) 将 YYYYMMDD 格式的时间作为备份日志文件名的一部分 （dateext）4) 日志最多保存 365 天 （maxage 365）5) 备份的日志文件保留 99 份 （rotate 99）6) &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/wtmp/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] wtmp 日志保存时间默认策略的设置 （设置 last 命令可以显示多久以前记录）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p>如果是 Rocky Linux &amp; RHEL：</p>



<pre class="wp-block-code"><code># cat /etc/logrotate.conf
......
/var/log/wtmp {
    monthly
    create 0664 root utmp
        minsize 1M
    rotate 1
}
......</code></pre>



<p>（<br>补充：<br>1) 影响的日志文件有 /var/log/wtmp （/var/log/wtmp）<br>2) 每月将现在的日志文件进行备份并生成新的日志文件 （monthly）<br>3) 日志文件权限是 0644 所属主是 root （create 0664 root utmp）<br>4) 只有当日志文件超过 1 M 时，且达到备份的时间才会开始备份<br>5) 备份的日志文件保留 5 份 （rotate 1）<br>）</p>



<p>如果是 openSUSE &amp; SLE：</p>



<pre class="wp-block-code"><code># cat /etc/logrotate.d/wtmp
/var/log/wtmp /var/log/btmp {
    compress
    dateext
    maxage 365
    rotate 99
    size=+400k
    notifempty
    missingok
    copytruncate
}</code></pre>



<p>（<br>补充：<br>1) 影响的日志文件有 /var/log/wtmp 和 /var/log/btmp （/var/log/wtmp /var/log/btmp）<br>2) 对备份的日志文件进行压缩 （compress）<br>3) 将 YYYYMMDD 格式的时间作为备份日志文件名的一部分 （dateext）<br>4) 日志最多保存 365 天 （maxage 365）<br>5) 备份的日志文件保留 99 份 （rotate 99）<br>6) 现在的日志文件超过 400 k 就开始备份，不用考虑备份时间，且备份时间的相关设置也将无效 （size=+400k）<br>7) 如果现有日志文件是空文件，则不再对日志文件进行备份 （notifempty）<br>8) 如果现有日志文件丢失，则不报错直接生成新的日志文件 （missingok）<br>）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux sudo 命令安全的加强</title>
		<link>https://eternalcenter-sep-2022.github.io/sudo-secure-enhance/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 17 Jun 2022 03:20:21 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Privilege (系统权限)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Setting (系统设置)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=24376</guid>

					<description><![CDATA[仅让 use pty 可以使用 sudo 命令 （避免后台进程使用 sudo 命令） 或者： 添加以下内容：]]></description>
										<content:encoded><![CDATA[
<p>仅让 use pty 可以使用 sudo 命令 （避免后台进程使用 sudo 命令）</p>



<pre class="wp-block-code"><code># vim /etc/sudoers</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># visudo</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
Defaults use_pty</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] Linux sudo 日志的开启</title>
		<link>https://eternalcenter-sep-2022.github.io/sudo-log/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 17 Jun 2022 03:14:07 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Log (系统日志)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Privilege (系统权限)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Security Log (系统安全日志)]]></category>
		<category><![CDATA[System Setting (系统设置)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=24372</guid>

					<description><![CDATA[步骤一：开启 sudo 日志 或者： 添加以下内容： 步骤二：显示 sudo 日志 2.1 退出后重新登录 （步骤略） 2.2 显示 sudo 日志]]></description>
										<content:encoded><![CDATA[
<h3>步骤一：开启 sudo 日志</h3>



<pre class="wp-block-code"><code># vim /etc/sudoers</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># visudo</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
Defaults logfile="/var/log/sudo.log"</code></pre>



<h3>步骤二：显示 sudo 日志</h3>



<h4>2.1 退出后重新登录</h4>



<p>（步骤略）</p>



<h4>2.2 显示 sudo 日志</h4>



<pre class="wp-block-code"><code># cat /var/log/sudo.log</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 显示可以无密码登录系统的用户 （以 1 行的形式显示）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-login-check/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 11 Jun 2022 13:33:07 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation (系统操作)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System User (系统用户)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=23846</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：显示可以登录系统的用户 （以 1 行到形式显示）作用：显示可以登录系统的用户 （以 1 行到形式显示） 使用方法 1. 给此脚本添加执行权限2. 执行此脚本 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：显示可以登录系统的用户 （以 1 行到形式显示）<br>作用：显示可以登录系统的用户 （以 1 行到形式显示）</p>



<h3>使用方法</h3>



<p>1. 给此脚本添加执行权限<br>2. 执行此脚本</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

userlist=
n=`cat /etc/passwd | wc -l`
i=1

while &#91; $i -le $n ]
do
	line=`sed -n "$&#91;i]p" /etc/passwd`
	echo $line | egrep "nologin$|false$" &amp;&gt; /dev/null
	if &#91; $? -ne 0 ];then
                userlist="$userlist `echo $line | awk -F: '{print $1}'`"
	fi
	let i++
done

echo $userlist</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[排错] 解决 Linux 执行 crontab -e 命令时报错 “You (&#8230;&#8230;) are not allowed to use this program (crontab)”</title>
		<link>https://eternalcenter-sep-2022.github.io/debug-you-are-not-allowed-to-use-this-program-crontab/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 10 Jun 2022 10:07:51 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation (系统操作)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Performance (系统性能)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Privilege (系统权限)]]></category>
		<category><![CDATA[System Process (系统进程)]]></category>
		<category><![CDATA[System Process & System Performance (系统进程 & 系统性能)]]></category>
		<category><![CDATA[System Process Security (系统进程安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Setting (系统设置)]]></category>
		<category><![CDATA[System User (系统用户)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=23780</guid>

					<description><![CDATA[解决方法 如果在系统中没有 /etc/cron.deny 配置文件，在 /etc/cron.allow 配置文件中添加要使用 crontab -e 命令的用户 添加以下内容： （补充：这里以添加用户 zhumingyu 为例） 如果在系统中没有 /etc/cron.allow 配置文件，在 /etc/cron.allow 配置文件中删除要使用 crontab -e 命令的用户 删除以下内容： （补充：这里以删除用户 zhumingyu 为例）]]></description>
										<content:encoded><![CDATA[
<h2>解决方法</h2>



<p>如果在系统中没有 /etc/cron.deny 配置文件，在 /etc/cron.allow 配置文件中添加要使用 crontab -e 命令的用户</p>



<pre class="wp-block-code"><code># vim /etc/cron.allow</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
zhumingyu</code></pre>



<p>（补充：这里以添加用户 zhumingyu 为例）</p>



<p>如果在系统中没有 /etc/cron.allow 配置文件，在 /etc/cron.allow 配置文件中删除要使用 crontab -e 命令的用户</p>



<pre class="wp-block-code"><code># vim /etc/cron.allow</code></pre>



<p>删除以下内容：</p>



<pre class="wp-block-code"><code>......
zhumingyu
......</code></pre>



<p>（补充：这里以删除用户 zhumingyu 为例）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[排错] 解决 Linux 执行 iptables 命令时报错 “iptables: No chain/target/match by that name.”</title>
		<link>https://eternalcenter-sep-2022.github.io/debug-iptables-no-chain-target-match-by-that-name/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 09 Jun 2022 12:24:34 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Computer & System Hardware & System Installation & System Upgradation (系统电脑 & 系统硬件 & 系统安装 & 系统升级)]]></category>
		<category><![CDATA[System Firewall (系统防火墙)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Upgradation (系统升级)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=23749</guid>

					<description><![CDATA[分析 系统运行的 kernel 内核已经被删除，此 kernel 内核相关的文件集都已经被删除，包括 ko 文件。安装新版本的 kernel 内核，并重启选择新版本的 kernel 内核，就能修复相关 kernel 内核文件集。 解决方法 步骤一：更新 kernel 内核 如果是 Rocky Linux &#38; RHEL： 如果是 openSUSE &#38; SLE： 步骤二：重启系统]]></description>
										<content:encoded><![CDATA[
<h2>分析</h2>



<p>系统运行的 kernel 内核已经被删除，此 kernel 内核相关的文件集都已经被删除，包括 ko 文件。安装新版本的 kernel 内核，并重启选择新版本的 kernel 内核，就能修复相关 kernel 内核文件集。</p>



<h2>解决方法</h2>



<h3>步骤一：更新 kernel 内核</h3>



<p>如果是 Rocky Linux &amp; RHEL：</p>



<pre class="wp-block-code"><code># yum update kernel*</code></pre>



<p>如果是 openSUSE &amp; SLE：</p>



<pre class="wp-block-code"><code># zypper update kernel*</code></pre>



<h3>步骤二：重启系统</h3>



<pre class="wp-block-code"><code># reboot</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux 某个所属组里有哪些用户的显示</title>
		<link>https://eternalcenter-sep-2022.github.io/group-display/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 08 Jun 2022 02:50:05 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation (系统操作)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Privilege (系统权限)]]></category>
		<category><![CDATA[System Privilege Security (系统权限安全)]]></category>
		<category><![CDATA[System Process Security (系统进程安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage (系统存储)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<category><![CDATA[System User (系统用户)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=23715</guid>

					<description><![CDATA[方法一：通过 /etc/group 配置文件显示某个附属所属组里有哪些用户 （注意：此方法并不能显示出把这些所属组当作主要所属组的用户） 方法二：通过 /etc/passwd 配置文件和 id 命令等显示主要所属组和附属所属组 （补充：可以通过肉眼比对此命令的输出结果来判断其主要所属组和附属所属组）]]></description>
										<content:encoded><![CDATA[
<h3>方法一：通过 /etc/group 配置文件显示某个附属所属组里有哪些用户</h3>



<pre class="wp-block-code"><code># cat /etc/group</code></pre>



<p>（注意：此方法并不能显示出把这些所属组当作主要所属组的用户）</p>



<h3>方法二：通过 /etc/passwd 配置文件和 id 命令等显示主要所属组和附属所属组</h3>



<pre class="wp-block-code"><code># for i in `cat /etc/passwd | egrep -v "nologin$|false$|half|sync|shutdown|halt" | awk -F: '{print $1}'`; do id $i; done | sort -k2</code></pre>



<p>（补充：可以通过肉眼比对此命令的输出结果来判断其主要所属组和附属所属组）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux 用户登录记录的显示</title>
		<link>https://eternalcenter-sep-2022.github.io/login-login-display/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Tue, 07 Jun 2022 08:28:00 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Log (系统日志)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation (系统操作)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Security Log (系统安全日志)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=23713</guid>

					<description><![CDATA[方法一：使用 last 命令 方法二：查看系统日志 如果是 openSUSE &#38; SLE 将以下内容： （注意：必须在 /etc/ssh/sshd_config 配置文档里设置了 LogLevel INFO 参数和 SyslogFacility AUTH 参数以后此方法才会有效） 如果是 Rocky Linux &#38; CentOS Linux &#38; RHEL： 或者： （注意：必须在 /etc/ssh/sshd_config 配置文档里设置了 LogLevel INFO 参数和 SyslogFacility AUTH 参数以后此方法才会有效）]]></description>
										<content:encoded><![CDATA[
<h3>方法一：使用 last 命令</h3>



<pre class="wp-block-code"><code># last | grep pts</code></pre>



<h3>方法二：查看系统日志</h3>



<p>如果是 openSUSE &amp; SLE 将以下内容：</p>



<pre class="wp-block-code"><code># cat /var/log/messages | grep systemd-logind</code></pre>



<p>（注意：必须在 /etc/ssh/sshd_config 配置文档里设置了 LogLevel INFO 参数和 SyslogFacility AUTH 参数以后此方法才会有效）</p>



<p>如果是 Rocky Linux &amp; CentOS Linux &amp; RHEL：</p>



<pre class="wp-block-code"><code># cat /var/log/secure | grep systemd-logind</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># cat /var/log/messages | grep systemd-logind</code></pre>



<p>（注意：必须在 /etc/ssh/sshd_config 配置文档里设置了 LogLevel INFO 参数和 SyslogFacility AUTH 参数以后此方法才会有效）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux SSH 常用安全加强配置项</title>
		<link>https://eternalcenter-sep-2022.github.io/sshd-security-enhance/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 06 Jun 2022 15:43:57 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Setting (系统设置)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=23701</guid>

					<description><![CDATA[内容一：SSH 的配置文件 1.1 SSH 配置文件的位置 1.2 SSH 配置文件的所属主、所属组和权限 1.2.1 确保 SSH 配置文件的所属主和所属组都是 root 1.2.2 确保 SSH 配置文件的权限是 640 内容二：SSH 常用安全加强配置项 2.1 将 SSH 设置为 v2 版本 2.1.1 将 SSH 设置为 v2 版本的配置参数 2.1.2 将 SSH 设置为 v2 版本的参考步骤 2.2 忽略 Rhosts 认证 2.2.1 忽略 Rhosts 认证的配置参数 2.2.2 设置忽略 Rhosts 认证的参考步骤 2.3 禁止受信任的客户端通过 .rhosts 或 /etc/hosts.equiv &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/sshd-security-enhance/" class="more-link">Continue reading<span class="screen-reader-text"> "[内容] Linux SSH 常用安全加强配置项"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3>内容一：SSH 的配置文件</h3>



<h4>1.1 SSH 配置文件的位置</h4>



<pre class="wp-block-code"><code>/etc/ssh/sshd_config</code></pre>



<h4>1.2 SSH 配置文件的所属主、所属组和权限</h4>



<h5>1.2.1 确保 SSH 配置文件的所属主和所属组都是 root</h5>



<pre class="wp-block-code"><code># chown root:root /etc/ssh/sshd_config</code></pre>



<h5>1.2.2 确保 SSH 配置文件的权限是 640</h5>



<pre class="wp-block-code"><code># chmod 640 /etc/ssh/sshd_config</code></pre>



<h3>内容二：SSH 常用安全加强配置项</h3>



<h4>2.1 将 SSH 设置为 v2 版本</h4>



<h5>2.1.1 将 SSH 设置为 v2 版本的配置参数</h5>



<pre class="wp-block-code"><code>Protocol 2</code></pre>



<h5>2.1.2 将 SSH 设置为 v2 版本的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*Protocol .*/Protocol 2/g' /etc/ssh/sshd_config</code></pre>



<h4>2.2 忽略 Rhosts 认证</h4>



<h5>2.2.1 忽略 Rhosts 认证的配置参数</h5>



<pre class="wp-block-code"><code>IgnoreRhosts yes</code></pre>



<h5>2.2.2 设置忽略 Rhosts 认证的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/^.*IgnoreRhosts .*/IgnoreRhosts yes/g' /etc/ssh/sshd_config</code></pre>



<h4>2.3 禁止受信任的客户端通过 .rhosts 或 /etc/hosts.equiv 进行认证</h4>



<h5>2.3.1 设置禁止受信任的客户端通过 .rhosts 或 /etc/hosts.equiv 进行认证的配置参数</h5>



<pre class="wp-block-code"><code>HostbasedAuthentication no</code></pre>



<h5>2.3.2 设置禁止受信任的客户端通过 .rhosts 或 /etc/hosts.equiv 进行认证的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*HostbasedAuthentication .*/HostbasedAuthentication no/g' /etc/ssh/sshd_config</code></pre>



<h4>2.4 禁止使用用户提交的 SSH 环境</h4>



<h5>2.4.1 设置禁止使用用户提交的 SSH 环境的配置参数</h5>



<pre class="wp-block-code"><code>PermitUserEnvironment no</code></pre>



<h5>2.4.2 设置禁止使用用户提交的 SSH 环境的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*PermitUserEnvironment .*/PermitUserEnvironment no/g' /etc/ssh/sshd_config</code></pre>



<h4>2.5 禁止 root 用户通过 SSH 登录</h4>



<h5>2.5.1 禁止 root 用户通过 SSH 登录的配置参数</h5>



<pre class="wp-block-code"><code>PermitRootLogin no</code></pre>



<h5>2.5.2 设置禁止 root 用户通过 SSH 登录的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*PermitRootLogin .*/PermitRootLogin no/g' /etc/ssh/sshd_config</code></pre>



<h4>2.6 禁止空密码 SSH 登录</h4>



<h5>2.6.1 禁止空密码 SSH 登录的配置参数</h5>



<pre class="wp-block-code"><code>PermitEmptyPasswords no</code></pre>



<h5>2.6.2 设置禁止空密码 SSH 登录的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*PermitEmptyPasswords .*/PermitEmptyPasswords no/g' /etc/ssh/sshd_config</code></pre>



<h4>2.7 将 SSH 登录信息写入系统日志</h4>



<h5>2.7.1 将 SSH 登录信息写入系统日志的配置参数</h5>



<pre class="wp-block-code"><code>SyslogFacility AUTH</code></pre>



<h5>2.7.2 设置将 SSH 登录信息写入系统日志的参看步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*SyslogFacility .*/SyslogFacility AUTH/g' /etc/ssh/sshd_config</code></pre>



<h4>2.8 记录全部 SSH 信息</h4>



<h5>2.8.1 记录全部 SSH 信息的配置参数</h5>



<pre class="wp-block-code"><code>LogLevel INFO</code></pre>



<h5>2.8.2 设置记录全部 SSH 信息的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*LogLevel .*/LogLevel INFO/' /etc/ssh/sshd_config</code></pre>



<h4>2.9 设置最大尝试登录失败数和触发尝试登录失败日志的登录失败数</h4>



<h5>2.9.1 设置最大尝试登录失败数和触发尝试登录失败日志的登录失败数的配置参数</h5>



<pre class="wp-block-code"><code>MaxAuthTries 5</code></pre>



<p>（补充：这里以设置最大尝试登录失败数是 5 次为例，如果此时尝试登录次数超过 2，则系统日志中会出现登录失败的记录）</p>



<h5>2.9.2 设置最大尝试登录失败数和触发尝试登录失败日志的登录失败数的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*MaxAuthTries .*/MaxAuthTries 5/g' /etc/ssh/sshd_config</code></pre>



<p>（补充：这里以设置最大尝试登录失败数是 5 次为例，如果此时尝试登录次数超过 2，则系统日志中会出现登录失败的记录）</p>



<h4>2.10 设置 SSH 登录时密码输入的时间</h4>



<h5>2.10.1 设置 SSH 登录时密码输入的时间的配置参数</h5>



<pre class="wp-block-code"><code>LoginGraceTime 600</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>LoginGraceTime 10m</code></pre>



<p>（补充：这里以设置 SSH 登录时密码输入的时间为 600 秒为例）</p>



<h5>2.10.2 设置 SSH 登录时密码输入的时间都参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*LoginGraceTime .*/LoginGraceTime 600/g' /etc/ssh/sshd_config</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># sed -i 's/.*LoginGraceTime .*/LoginGraceTime 10m/g' /etc/ssh/sshd_config</code></pre>



<p>（补充：这里以设置 SSH 登录时密码输入的时间为 600 秒为例）</p>



<h4>2.11 禁止 SSH 图形界面转发</h4>



<h5>2.11.1 禁止 SSH 图形界面转发的配置参数</h5>



<pre class="wp-block-code"><code>X11Forwarding no</code></pre>



<h5>2.11.1 设置禁止 SSH 图形界面转发的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*X11Forwarding .*/X11Forwarding no/g' /etc/ssh/sshd_config</code></pre>



<h4>2.12 禁止 SSH TCP 转发</h4>



<h5>2.12.1 设置禁止 SSH TCP 转发的配置参数</h5>



<pre class="wp-block-code"><code>AllowTcpForwarding no</code></pre>



<h5>2.12.2 设置禁止 SSH TCP 转发的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*AllowTcpForwarding .*/AllowTcpForwarding no/g' /etc/ssh/sshd_config</code></pre>



<h4>2.13 不显示上次 SSH 登录的信息，例如时间和地点等</h4>



<h5>2.13.1 设置不显示上次 SSH 登录的信息，例如时间和地点等的配置参数</h5>



<pre class="wp-block-code"><code>PrintMotd no</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>PrintLastLog no</code></pre>



<h5>2.13.1 设置不显示上次 SSH 登录的信息，例如时间和地点等的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*PrintMotd .*/PrintMotd no/g' /etc/ssh/sshd_config</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># sed -i 's/.*PrintLastLog .*/PrintLastLog no/g' /etc/ssh/sshd_config</code></pre>



<h4>2.14 设置同时只能让几个 SSH 用户登录</h4>



<h5>2.14.1 设置同时只能让几个 SSH 用户登录的配置参数</h5>



<pre class="wp-block-code"><code>MaxStartups 10:30:60</code></pre>



<p>（<br>补充：这里以<br>1) 最多同时只能让 10 个用户发起 SSH 登录请求，超过此数量的登录请求会被拒绝<br>2) 当 SSH 连接数超过上限时 （这里设置的是 10 个），再新发起 SSH 登录请求的用户，会有 30% 的概率被拒绝<br>3) 当 SSH 连接数超过 60 时，再新发起 SSH 登录请求的用户全部会被拒绝，这里的 30 参数将会无效<br>）</p>



<h5>2.14.2 设置同时只能让几个 SSH 用户登录的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*MaxStartups .*/MaxStartups 10:30:60/g' /etc/ssh/sshd_config</code></pre>



<p>（<br>补充：这里以<br>1) 最多同时只能让 10 个用户发起 SSH 登录请求，超过此数量的登录请求会被拒绝<br>2) 当 SSH 连接数超过上限时 （这里设置的是 10 个），再新发起 SSH 登录请求的用户，会有 30% 的概率被拒绝<br>3) 当 SSH 连接数超过 60 时，再新发起 SSH 登录请求的用户全部会被拒绝，这里的 30 参数将会无效<br>）</p>



<h4>2.15 设置每个连接可以开启会话的个数</h4>



<h5>2.15.1 设置每个连接可以开启会话的个数的配置参数</h5>



<pre class="wp-block-code"><code>MaxSessions 4</code></pre>



<p>（补充：这里以设置每个连接可以开启 4 个会话为例，默认值为 10）</p>



<h5>2.15.2 设置每个连接可以开启会话的个数的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*MaxSessions .*/MaxSessions 4/g' /etc/ssh/sshd_config</code></pre>



<p>（补充：这里以设置每个连接可以开启 4 个会话为例，默认值为 10）</p>



<h4>2.16 设置客户端 SSH 空闲超时时间</h4>



<h5>2.16.1 设置客户端 SSH 空闲超时时间的配置参数</h5>



<pre class="wp-block-code"><code>ClientAliveInterval 100
ClientAliveCountMax 3</code></pre>



<p>（补充：这里以设置客户端 SSH 空闲超时时间为 100 * 3=300 秒为例）</p>



<h5>2.16.2 设置客户端 SSH 空闲超时时间的参考步骤</h5>



<pre class="wp-block-code"><code># sed -i 's/.*ClientAliveInterval .*/ClientAliveInterval 100/g' /etc/ssh/sshd_config
# sed -i 's/.*ClientAliveCountMax .*/ClientAliveCountMax 3/g' /etc/ssh/sshd_config</code></pre>



<p>（补充：这里以设置客户端 SSH 空闲超时时间为 100 * 3=300 秒为例）</p>



<h4>2.17 指定安全的 SSH Ciphers 加密算法</h4>



<h5>2.17.1 设置 SSH Ciphers 加密算法的配置参数</h5>



<pre class="wp-block-code"><code>Ciphers aes256-ctr,aes192-ctr,aes128-ctr</code></pre>



<p>（补充：这里以使用 aes256-ctr、aes192-ctr 和 aes128-ctr SSH Ciphers 加密算法为例）</p>



<h5>2.17.2 设置 SSH Ciphers 加密算法的参考步骤</h5>



<pre class="wp-block-code"><code># echo "Ciphers aes256-ctr,aes192-ctr,aes128-ctr" &gt;&gt; /etc/ssh/sshd_config</code></pre>



<p>（补充：这里以使用 aes256-ctr、aes192-ctr 和 aes128-ctr SSH Ciphers 加密算法为例）</p>



<h4>2.18 指定安全的 SSH MACs 加密算法</h4>



<h5>2.18.1 设置 SSH MACs 加密算法的配置参数</h5>



<pre class="wp-block-code"><code>MACs hmac-sha2-512,hmac-sha2-256</code></pre>



<p>（补充：这里以使用 hmac-sha2-512 和 hmac-sha2-256 SSH MACs 加密算法为例）</p>



<h5>2.18.2 设置 SSH MACs 加密算法的参考步骤</h5>



<pre class="wp-block-code"><code># echo "MACs hmac-sha2-512,hmac-sha2-256" &gt;&gt; /etc/ssh/sshd_config</code></pre>



<p>（补充：这里以使用 hmac-sha2-512 和 hmac-sha2-256 SSH MACs 加密算法为例）</p>



<h4>2.19 指定安全的 SSH KexAlgorithms 加密算法</h4>



<h5>2.19.1 设置 SSH KexAlgorithms 加密算法的配置参数</h5>



<pre class="wp-block-code"><code>KexAlgorithms ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256</code></pre>



<p>（补充：这里以使用 ecdh-sha2-nistp521、ecdh-sha2-nistp384、ecdh-sha2-nistp256 和 diffie-hellman-group-exchange-sha256 SSH KexAlgorithms 加密算法为例）</p>



<h5>2.19.2 设置 SSH KexAlgorithms 加密算法的参考步骤</h5>



<pre class="wp-block-code"><code># echo "KexAlgorithms ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256" &gt;&gt; /etc/ssh/sshd_config</code></pre>



<p>（补充：这里以使用 ecdh-sha2-nistp521、ecdh-sha2-nistp384、ecdh-sha2-nistp256 和 diffie-hellman-group-exchange-sha256 SSH KexAlgorithms 加密算法为例）</p>



<h4>2.20 只允许某 IP 地址可以 SSH 本服务器</h4>



<h5>2.20.1 启用 UseTCPWrappers 参数</h5>



<pre class="wp-block-code"><code># vim /etc/ssh/sshd_config</code></pre>



<p>将部分内容修改如下：</p>



<pre class="wp-block-code"><code>......
UseTCPWrappers yes
......</code></pre>



<h5>2.20.2 禁止所有 IP 地址可以 SSH 本服务器</h5>



<pre class="wp-block-code"><code># vim /etc/hosts.deny</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
sshd : ALL </code></pre>



<h5>2.20.3 只允许某 IP 地址可以 SSH 本服务器</h5>



<pre class="wp-block-code"><code># vim /etc/hosts.deny</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
sshd : 192.168.0.1/32 : ALLOW
sshd : ALL</code></pre>



<p>（补充：这里以允许 IP 地址 192.168.0.1 可以 SSH 本服务器为例）</p>



<p>（注意：这和防火墙的策略一样从上往下匹配及停止，所以允许某 IP 地址可以 SSH 本服务器的策略一定要加在禁止所有 IP 地址可以 SSH 本服务器的策略之前）</p>



<h4>2.21 只允许从某 IP 地址来的某用户可以 SSH 本服务器</h4>



<pre class="wp-block-code"><code># vim /etc/ssh/sshd_config</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
AllowUsers zhumingyu mingyuzhu@192.168.1.1
AllowGroups zhu</code></pre>



<p>（<br>补充：这里以<br>1) 允许用户 zhumingyu 可以登录<br>2) 允许从 192.168.1.1 来的用户 mingyuzhu 可以登录<br>3) 允许属于组 zhu 的用户可以登录<br>其它用户不能登录<br>为例<br>）</p>



<h4>2.22 禁止某 IP 地址可以 SSH 本服务器</h4>



<h5>2.22.1 启用 UseTCPWrappers 参数</h5>



<pre class="wp-block-code"><code># vim /etc/ssh/sshd_config</code></pre>



<p>将部分内容修改如下：</p>



<pre class="wp-block-code"><code>......
UseTCPWrappers yes
......</code></pre>



<h5>2.22.2 禁止某 IP 地址可以 SSH 本服务器</h5>



<pre class="wp-block-code"><code># vim /etc/hosts.deny</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>sshd : 192.168.0.1/32 : ALLOW</code></pre>



<p>（补充：这里以禁止 IP 地址 192.168.0.1 可以 SSH 本服务器为例）</p>



<h4>2.23 禁止从某 IP 地址来的某用户可以 SSH 本服务器</h4>



<pre class="wp-block-code"><code># vim /etc/ssh/sshd_config</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
DenyUsers zhumingyu mingyuzhu@192.168.1.1
DenyGroups zhu</code></pre>



<p>（<br>补充：这里以<br>1) 禁止用户 zhumingyu 登录<br>2) 禁止从 192.168.1.1 来的用户 mingyuzhu 登录<br>3) 禁止属于组 zhu 的用户登录<br>其它用户都可以登录<br>为例<br>）</p>



<h3>内容三：重启 sshd 服务</h3>



<pre class="wp-block-code"><code># systemctl restart sshd</code></pre>



<p>（补充：内容二里的参数只有重启了 sshd 服务后才能生效）</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
