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 Login Security (系统登录安全)

Posted on February 17, 2023October 5, 2024

[步骤] Linux SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm) 的设置 (Ciphers 参数、MACs 参数和 KexAlgorithms 参数的设置) (RHEL 8 版)

正文:

步骤一:确定 CRYPTO_POLICY 参数没有生效

# vim /etc/sysconfig/sshd

确保部分内容如下:

......
# CRYPTO_POLICY=
......

步骤二:在 /etc/crypto-policies/back-ends/opensshserver.config 配置文件中确认要使用的 Ciphers、MACs 和 KexAlgorithm 参数

2.1 备份 /etc/crypto-policies/back-ends/opensshserver.config 配置文件

# cp /etc/crypto-policies/back-ends/opensshserver.config /etc/crypto-policies/back-ends/opensshserver.config.backup

2.2 修改 /etc/crypto-policies/back-ends/opensshserver.config 配置文件

# vim /etc/crypto-policies/back-ends/opensshserver.config

添加需要使用的 SSH 算法 (algorithms) 和加密方式 (ciphers):

(内容略)

(注意:如果需要使用的 SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm) ,已包含在其中了则可以不用添加)

2.3 显示目前正在被使用的 SSH 算法 (algorithms) 和加密方式 (ciphers)

# 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

(补充:这里以显示 RHEL 8 默认使用的 SSH 加密方式 (cipher)、信息验证代码 (message authentication code) 和算法 (algorithm) 为例)

步骤三:让在 /etc/crypto-policies/back-ends/opensshserver.config 配置文件中添加要使用的 SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm) 生效

# systemctl restart sshd

步骤四:测试 SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm)

4.1 测试 SSH 加密方式 (ciphers)

4.1.1 测试某个 SSH 加密方式 (cipher)
# ssh -vv -oCiphers=3des-cbc -oPort=22 192.168.0.1

(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 3des-cbc SSH 加密方式 (cipher) 为例)

4.1.2 测试多个 SSH 加密方式 (cipher)
# ssh -vv -oCiphers=3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc -oPort=22 192.168.0.1

(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 3des-cbc、aes128-cbc、aes192-cbc 和 aes256-cbc SSH 加密方式 (cipher) 为例)

4.2 测试 SSH 信息验证代码 (message authentication code)

4.2.1 测试某个 SSH 信息验证代码 (message authentication code)
# ssh -vv -oMACs=hmac-md5 -oPort=22 192.168.0.1

(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 hmac-md5 SSH 信息验证代码 (message authentication code) 为例)

4.2.2 测试多个 SSH 信息验证代码 (message authentication 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

(补充:这里以测试 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 信息验证代码 (message authentication code) 为例)

4.3 显示所有在使用的 SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm)

4.3.1 使用 sshd 命令显示所有在使用的加密方式 (cipher) 、信息验证代码 (message authentication code)
# sshd -T | egrep -i "ciphers|macs"
4.3.2 使用 nmap 命令显示所有在使用的 SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm)
# nmap --script ssh2-enum-algos -sV -p 22 127.0.0.1

(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22 为例)

参考文献:

https://access.redhat.com/solutions/4410591
https://access.redhat.com/solutions/4278651

Posted on February 17, 2023November 22, 2024

[内容] Linux 功能的限制

正文:通过 /etc/security/access.conf 文件实现 Linux 功能使用的限制

# vim /etc/security/access.conf

添加以下内容:

......
+ : root : LOCAL
+ : zhumingyu : ALL
+ : @cron : ALL
- : ALL : ALL

(
补充:这里以
1) 允许 root 用户使用本地的所有功能
2) 允许 zhumingyu 用户使用所有功能
3) 允许 cron 功能被所有用户使用
4) 其它所有的功能或用户都被禁止
为例
)

补充:使 /etc/security/access.conf 文件的配置失效

# vim /etc/pam.d/crond

将部分内容修改如下:

......
#account required pam_access.so
......
Posted on October 28, 2022November 25, 2022

[COMMAND] Linux Command lslogins (Display user password login, password deny and last-login)

Content One: Display all users’ password login, password deny and last-login

# lslogins

Content Two: Display a user’s password login, password deny and last-login

# lslogins <user>
Posted on September 9, 2022November 22, 2024

[内容] Linux 密码文件 /etc/shadow 的介绍 (显示用户密码相关的策略)

内容一:/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) 如果是 2 个感叹号 “!!” 则代表从来都没有设置过密码
3) 如果为空则代表没有设置密码
4) 如果是 1 个星号 “*” 则代表用户被锁定,但是其它登陆方式不受限制,例 SSH 登陆
5) 如果是 1 个感叹号 “!” 则代表用户被锁定,但是其它登陆方式不受限制,例 SSH 登陆
6) 如果以 1 个感叹号开头 “!” 则代表用户被锁定
7) 如果以 2 个感叹号开头 “!!” 则代表用户被锁定

2.2.2 查看命令
# cut -d: -f1,7
2.2.3 修改命令
# passwd <user>

2.3 第 3 段内容:密码最后的修改日期

2.3.1 内容的含义

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

2.3.2 查看命令
# egrep ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1,3

或者:

# chage -l <user> | grep 'Last password change'
2.3.3 修改命令
# chage -d <date> <user>

或者:

# chage --lastday <date> <user>

2.4 第 4 段内容:修改密码最短天数间隔

2.4.1 内容的含义

两次修改密码最短天数间隔

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

2.4.2 查看命令
# egrep ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1,4

或者:

# chage -l <user> | grep 'Minimum number of days between password change'
2.4.3 修改命令
# chage -m <days> <user>

或者:

# chage --mindays <days> <user>

2.5 第 5 段内容:密码过期的天数

2.5.1 内容的含义

修改密码后过多少天会过期

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

2.5.2 查看命令
# egrep ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1,5

或者:

# chage -l <user> | grep 'Maximum number of days between password change'
2.5.3 修改命令
# chage -M <days> <user>

或者:

# chage --maxdays <days> <user>

2.6 第 6 段内容:密码过期前提前多少天发出警告

2.6.1 内容的含义

密码过期前,提前多少天发出警告

如果为空则代表不发出警告

2.6.2 查看命令
# egrep ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1,6

或者:

# chage -l <user> | grep 'Number of days of warning before password expires'
2.6.3 修改密码
# chage -W <days> <user>

或者:

# chage --warndays <days> <user>

2.7 第 7 段内容:密码失效的天数

2.7.1 内容的含义

密码过期后过多少天会失效

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

2.7.2 查看命令
# egrep ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1,7

或者:

# chage -l <user> | grep 'Password inactive'
2.7.3 修改密码
# chage -I <days> <user>

或者:

# chage --inactive <days> <user>

2.8 第 8 段内容:用户的失效日期

2.8.1 内容的含义

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

2.8.2 查看命令
# egrep ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1,8

或者:

# chage -l <user> | grep 'Account expires'
2.8.3 修改密码
# chage -E <date> <user>

或者:

# chage --expiredate <date> <user>

2.9 第 9 段内容:保留

这是一个保留位,目前没有作用

Posted on August 29, 2022June 7, 2024

[步骤] Linux SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm) 的设置 (Ciphers、MACs 和 KexAlgorithms 参数的设置) (不使用来自 crypto policies 的系统全局设置) (RHEL 8 版)

注意:

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

正文:

步骤一:启用 SSH 配置文件里加密方式 (cipher) 、信息验证代码 (message authentication code)和算法 (algorithm) 的设置

1.1 备份 /etc/sysconfig/sshd 配置文件

# cp /etc/sysconfig/sshd /etc/sysconfig/sshd_backup

1.2 修改 /etc/sysconfig/sshd 配置文件

# vim /etc/sysconfig/sshd

将以下内容:

# CRYPTO_POLICY=

修改为:

......
CRYPTO_POLICY=
......

步骤二:在 /etc/ssh/sshd_config 配置文件中设置要使用的 Ciphers、MACs 和 KexAlgorithm 参数

2.1 备份 /etc/ssh/sshd_config 配置文件

# cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup

2.2 在 /etc/ssh/sshd_config 配置文件中添加要使用的 Ciphers、MACs 和 KexAlgorithms 参数

# vim /etc/ssh/sshd_config

添加以下内容:

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

(
补充:这里以使用:
1) aes256-ctr、aes192-ctr 和 aes128-ctr SSH 加密方式 (cipher)
2) hmac-sha2-512 和 hmac-sha2-256 SSH 信息验证代码 (message authentication code)
3) ecdh-sha2-nistp521、ecdh-sha2-nistp384、ecdh-sha2-nistp256 和 diffie-hellman-group-exchange-sha256 SSH 算法 (algorithm)
为例
)

2.3 让在 /etc/ssh/sshd_config 配置文件中添加要使用的 Ciphers、MACs 和 KexAlgorithms 参数生效

# systemctl restart sshd

步骤三:测试 SSH 加密方式 (cipher)和算法 (algorithm)

3.1 测试 SSH Ciphers 参数

3.1.1 测试某个 SSH 加密方式 (ciphers)
# ssh -vv -oCiphers=3des-cbc -oPort=22 192.168.0.1

(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 3des-cbc SSH 加密方式 (cipher) 为例)

3.1.2 测试多个 SSH 加密方式 (ciphers)
# ssh -vv -oCiphers=3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc -oPort=22 192.168.0.1

(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 3des-cbc、aes128-cbc、aes192-cbc 和 aes256-cbc SSH 加密方式 (cipher) 为例)

3.2 测试 SSH MACs 参数

3.2.1 测试某个 SSH ciphers 加密算法
# ssh -vv -oMACs=hmac-md5 -oPort=22 192.168.0.1

(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 hmac-md5 SSH 信息验证代码 (message authentication code) 为例)

3.2.2 测试多个 SSH ciphers 加密算法
# 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

(补充:这里以测试 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 信息验证代码 (message authentication code) 为例)

3.3 显示所有在使用的 SSH 加密方式 (cipher)和算法 (algorithm)

3.3.1 使用 sshd 命令显示所有在使用的 SSH 加密方式 (cipher)和信息验证代码 (message authentication code)
# sshd -T | egrep -i "ciphers|macs"
3.3.2 使用 nmap 命令显示所有在使用的 SSH 加密方式 (cipher)和算法 (algorithm)
# nmap --script ssh2-enum-algos -sV -p 22 127.0.0.1

(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22 为例)

参考文献:

https://access.redhat.com/solutions/4410591
https://access.redhat.com/solutions/4278651

Posts pagination

Previous page Page 1 … Page 6 Page 7 Page 8 … Page 24 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