Skip to content
Eternal Center

Eternal Center

  • Single-Node (单节点)
    • System (系统)
    • Service (服务)
    • Database (数据库)
    • Container (容器)
    • Virtualization (虚拟化)
  • Multi-Node (多节点)
    • Cluster (集群)
    • Big Data (大数据)
    • Cloud Computing (云计算)
    • Batch Processing (批量处理)
  • Approach (方式方法)
    • Languages (语言)
    • Ideas (思路)
    • Programing (编程)
    • Project (项目)
  • Eternity (永恒)
    • News (消息)
    • Creations (创作)
    • Classics (经典)
    • Legends (传说)
    • Chronicle (编年史)
    • FNIOS (宇宙公民开源学院)

Category: System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)

Posted on June 10, 2022November 22, 2024

[排错] 解决 Linux 执行 crontab -e 命令时报错 “You (……) are not allowed to use this program (crontab)”

解决方法

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

# vim /etc/cron.allow

添加以下内容:

......
zhumingyu

(补充:这里以添加用户 zhumingyu 为例)

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

# vim /etc/cron.allow

删除以下内容:

......
zhumingyu
......

(补充:这里以删除用户 zhumingyu 为例)

Posted on June 8, 2022July 9, 2023

[内容] Linux 某个所属组里有哪些用户的显示

方法一:通过 /etc/group 配置文件显示某个附属所属组里有哪些用户

# cat /etc/group

(注意:此方法并不能显示出把这些所属组当作主要所属组的用户)

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

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

(补充:可以通过肉眼比对此命令的输出结果来判断其主要所属组和附属所属组)

Posted on June 7, 2022June 3, 2024

[内容] Linux 用户登录记录的显示

方法一:使用 last 命令

# last | grep pts

方法二:查看系统日志

如果是 openSUSE & SLES 将以下内容:

# cat /var/log/messages | grep systemd-logind

(注意:必须在 /etc/ssh/sshd_config 配置文档里设置了 LogLevel INFO 参数和 SyslogFacility AUTH 参数以后此方法才会有效)

如果是 Rocky Linux & CentOS Linux & RHEL:

# cat /var/log/secure | grep systemd-logind

或者:

# cat /var/log/messages | grep systemd-logind

(注意:必须在 /etc/ssh/sshd_config 配置文档里设置了 LogLevel INFO 参数和 SyslogFacility AUTH 参数以后此方法才会有效)

Posted on June 6, 2022November 22, 2024

[内容] Linux SSH 常用安全加强配置项

内容一:SSH 的配置文件

1.1 SSH 配置文件的位置

/etc/ssh/sshd_config

1.2 SSH 配置文件的所属主、所属组和权限

1.2.1 确保 SSH 配置文件的所属主和所属组都是 root
# chown root:root /etc/ssh/sshd_config
1.2.2 确保 SSH 配置文件的权限是 640
# chmod 640 /etc/ssh/sshd_config

内容二:SSH 常用安全加强配置项

2.1 将 SSH 设置为 v2 版本

2.1.1 将 SSH 设置为 v2 版本的配置参数
Protocol 2
2.1.2 将 SSH 设置为 v2 版本的参考步骤
# sed -i 's/.*Protocol .*/Protocol 2/g' /etc/ssh/sshd_config

2.2 忽略 Rhosts 认证

2.2.1 忽略 Rhosts 认证的配置参数
IgnoreRhosts yes
2.2.2 设置忽略 Rhosts 认证的参考步骤
# sed -i 's/^.*IgnoreRhosts .*/IgnoreRhosts yes/g' /etc/ssh/sshd_config

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

2.3.1 设置禁止受信任的客户端通过 .rhosts 或 /etc/hosts.equiv 进行认证的配置参数
HostbasedAuthentication no
2.3.2 设置禁止受信任的客户端通过 .rhosts 或 /etc/hosts.equiv 进行认证的参考步骤
# sed -i 's/.*HostbasedAuthentication .*/HostbasedAuthentication no/g' /etc/ssh/sshd_config

2.4 禁止使用用户提交的 SSH 环境

2.4.1 设置禁止使用用户提交的 SSH 环境的配置参数
PermitUserEnvironment no
2.4.2 设置禁止使用用户提交的 SSH 环境的参考步骤
# sed -i 's/.*PermitUserEnvironment .*/PermitUserEnvironment no/g' /etc/ssh/sshd_config

2.5 禁止 root 用户通过 SSH 登录

2.5.1 禁止 root 用户通过 SSH 登录的配置参数
PermitRootLogin no
2.5.2 设置禁止 root 用户通过 SSH 登录的参考步骤
# sed -i 's/.*PermitRootLogin .*/PermitRootLogin no/g' /etc/ssh/sshd_config

2.6 禁止空密码 SSH 登录

2.6.1 禁止空密码 SSH 登录的配置参数
PermitEmptyPasswords no
2.6.2 设置禁止空密码 SSH 登录的参考步骤
# sed -i 's/.*PermitEmptyPasswords .*/PermitEmptyPasswords no/g' /etc/ssh/sshd_config

2.7 将 SSH 登录信息写入系统日志

2.7.1 将 SSH 登录信息写入系统日志的配置参数
SyslogFacility AUTH
2.7.2 设置将 SSH 登录信息写入系统日志的参看步骤
# sed -i 's/.*SyslogFacility .*/SyslogFacility AUTH/g' /etc/ssh/sshd_config

2.8 记录全部 SSH 信息

2.8.1 记录全部 SSH 信息的配置参数
LogLevel INFO
2.8.2 设置记录全部 SSH 信息的参考步骤
# sed -i 's/.*LogLevel .*/LogLevel INFO/' /etc/ssh/sshd_config

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

2.9.1 设置最大尝试登录失败数和触发尝试登录失败日志的登录失败数的配置参数
MaxAuthTries 5

(补充:这里以设置最大尝试登录失败数是 5 次为例,如果此时尝试登录次数超过 2,则系统日志中会出现登录失败的记录)

2.9.2 设置最大尝试登录失败数和触发尝试登录失败日志的登录失败数的参考步骤
# sed -i 's/.*MaxAuthTries .*/MaxAuthTries 5/g' /etc/ssh/sshd_config

(补充:这里以设置最大尝试登录失败数是 5 次为例,如果此时尝试登录次数超过 2,则系统日志中会出现登录失败的记录)

2.10 设置 SSH 登录时密码输入的时间

2.10.1 设置 SSH 登录时密码输入的时间的配置参数
LoginGraceTime 600

或者:

LoginGraceTime 10m

(补充:这里以设置 SSH 登录时密码输入的时间为 600 秒为例)

2.10.2 设置 SSH 登录时密码输入的时间都参考步骤
# sed -i 's/.*LoginGraceTime .*/LoginGraceTime 600/g' /etc/ssh/sshd_config

或者:

# sed -i 's/.*LoginGraceTime .*/LoginGraceTime 10m/g' /etc/ssh/sshd_config

(补充:这里以设置 SSH 登录时密码输入的时间为 600 秒为例)

2.11 禁止 SSH 图形界面转发

2.11.1 禁止 SSH 图形界面转发的配置参数
X11Forwarding no
2.11.1 设置禁止 SSH 图形界面转发的参考步骤
# sed -i 's/.*X11Forwarding .*/X11Forwarding no/g' /etc/ssh/sshd_config

2.12 禁止 SSH TCP 转发

2.12.1 设置禁止 SSH TCP 转发的配置参数
AllowTcpForwarding no
2.12.2 设置禁止 SSH TCP 转发的参考步骤
# sed -i 's/.*AllowTcpForwarding .*/AllowTcpForwarding no/g' /etc/ssh/sshd_config

2.13 不显示上次 SSH 登录的信息,例如时间和地点等

2.13.1 设置不显示上次 SSH 登录的信息,例如时间和地点等的配置参数
PrintMotd no

或者:

PrintLastLog no
2.13.1 设置不显示上次 SSH 登录的信息,例如时间和地点等的参考步骤
# sed -i 's/.*PrintMotd .*/PrintMotd no/g' /etc/ssh/sshd_config

或者:

# sed -i 's/.*PrintLastLog .*/PrintLastLog no/g' /etc/ssh/sshd_config

2.14 设置同时只能让几个 SSH 用户登录

2.14.1 设置同时只能让几个 SSH 用户登录的配置参数
MaxStartups 10:30:60

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

2.14.2 设置同时只能让几个 SSH 用户登录的参考步骤
# sed -i 's/.*MaxStartups .*/MaxStartups 10:30:60/g' /etc/ssh/sshd_config

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

2.15 设置每个连接可以开启会话的个数

2.15.1 设置每个连接可以开启会话的个数的配置参数
MaxSessions 4

(补充:这里以设置每个连接可以开启 4 个会话为例,默认值为 10)

2.15.2 设置每个连接可以开启会话的个数的参考步骤
# sed -i 's/.*MaxSessions .*/MaxSessions 4/g' /etc/ssh/sshd_config

(补充:这里以设置每个连接可以开启 4 个会话为例,默认值为 10)

2.16 设置客户端 SSH 空闲超时时间

2.16.1 设置客户端 SSH 空闲超时时间的配置参数
ClientAliveInterval 100
ClientAliveCountMax 3

(补充:这里以设置客户端 SSH 空闲超时时间为 100 * 3=300 秒为例)

2.16.2 设置客户端 SSH 空闲超时时间的参考步骤
# sed -i 's/.*ClientAliveInterval .*/ClientAliveInterval 100/g' /etc/ssh/sshd_config
# sed -i 's/.*ClientAliveCountMax .*/ClientAliveCountMax 3/g' /etc/ssh/sshd_config

(补充:这里以设置客户端 SSH 空闲超时时间为 100 * 3=300 秒为例)

2.17 禁止使用 RSA 进行 rhosts 的安全验证

2.17.1 设置禁止使用 RSA 进行 rhosts 的安全验证的参数
RhostsRSAAuthentication no
2.17.2 设置禁止使用 RSA 进行 rhosts 的安全验证的参考步骤
# sed -i 's/.*RhostsRSAAuthentication .*/RhostsRSAAuthentication no/g' /etc/ssh/sshd_config

2.18 禁止使用验证代理 (如果存在) 转发给远程服务器

2.18.1 设置禁止使用验证代理 (如果存在) 转发给远程服务器的参数
ForwardAgent no
2.18.2 设置禁止使用验证代理 (如果存在) 转发给远程服务器的参考步骤
# sed -i 's/.*ForwardAgent .*/ForwardAgent no/g' /etc/ssh/sshd_config

2.19 指定安全的 SSH Ciphers 加密算法

2.19.1 设置 SSH Ciphers 加密算法的配置参数
Ciphers aes256-ctr,aes192-ctr,aes128-ctr

(补充:这里以使用 aes256-ctr、aes192-ctr 和 aes128-ctr SSH Ciphers 加密算法为例)

2.19.2 设置 SSH Ciphers 加密算法的参考步骤
# echo "Ciphers aes256-ctr,aes192-ctr,aes128-ctr" >> /etc/ssh/sshd_config

(补充:这里以使用 aes256-ctr、aes192-ctr 和 aes128-ctr SSH Ciphers 加密算法为例)

2.20 指定安全的 SSH MACs 加密算法

2.20.1 设置 SSH MACs 加密算法的配置参数
MACs hmac-sha2-512,hmac-sha2-256

(补充:这里以使用 hmac-sha2-512 和 hmac-sha2-256 SSH MACs 加密算法为例)

2.20.2 设置 SSH MACs 加密算法的参考步骤
# echo "MACs hmac-sha2-512,hmac-sha2-256" >> /etc/ssh/sshd_config

(补充:这里以使用 hmac-sha2-512 和 hmac-sha2-256 SSH MACs 加密算法为例)

2.21 指定安全的 SSH KexAlgorithms 加密算法

2.21.1 设置 SSH KexAlgorithms 加密算法的配置参数
KexAlgorithms ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256

(补充:这里以使用 ecdh-sha2-nistp521、ecdh-sha2-nistp384、ecdh-sha2-nistp256 和 diffie-hellman-group-exchange-sha256 SSH KexAlgorithms 加密算法为例)

2.21.2 设置 SSH KexAlgorithms 加密算法的参考步骤
# echo "KexAlgorithms ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256" >> /etc/ssh/sshd_config

(补充:这里以使用 ecdh-sha2-nistp521、ecdh-sha2-nistp384、ecdh-sha2-nistp256 和 diffie-hellman-group-exchange-sha256 SSH KexAlgorithms 加密算法为例)

内容三:重启 sshd 服务

# systemctl restart sshd

(补充:内容二里的参数只有重启了 sshd 服务后才能生效)

补充:Linux SSH 访问的限制

Linux SSH 访问的限制
(Rocky Linux 8 & RHEL 8 版)
Linux SSH 访问的限制
(openSUSE & SLES & CentOS 7 & RHEL 7 版)
Linux SSH 只影响部分客户端访问的设置
Posted on June 6, 2022July 9, 2023

[工具] Shell 批量检测指定用户是否可以登录本地服务器

介绍

基本信息

作者:朱明宇
名称:批量检测指定用户是否可以登录本地服务器
作用:批量检测指定用户是否可以登录本地服务器

使用方法

1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本

脚本分割线里的变量

directorylist=”daemon bin sys adm uucp guest nobody lpd lp” #要被检测的用户

脚本

#!/bin/bash

####################### Separator ########################

directorylist="daemon bin sys adm uucp guest nobody lpd lp"

####################### Separator ########################

directorycheck=

for i in `echo $directorylist`
do
        directorycheck="$directorycheck `cat /etc/passwd | egrep "^$i:" | egrep -v '/sbin/nologin|false|/bin/false' | awk -F: '{print $1}'`"
done

echo $directorycheck

Posts pagination

Previous page Page 1 … Page 32 Page 33 Page 34 … Page 66 Next page

Aspiration (愿景):

Everyone can achieve self-achievement and self-happiness fairly

每个人都能公平地实现自我成就和自我幸福

Logo (徽标):

Additional Information (其他信息):

About     Manual     Clone     Contact
Disclaimer     Friendly Links     Donation

关于     手册     克隆     联系
免责声明     友情链接     捐赠

Search Inside Website (站内搜索)

Search Outside Website (站外搜索):

Google         Wikipedia         Bing

Eternal URL (永恒网址):

https://eternity.eternalcenter.com Will be last access method / 将是最后的访问方式

Proudly powered by LNMP Proudly powered by WordPress