8
0

常见系统安全和网络安全-1

2026-09-04
2026-09-04
常见系统安全和网络安全-1

1. 密码登录问题

主要问题存在于公网的ssh 22端口和root密码登录

非必须,不采用root直接登录,特别是root密码直接登录

有需要的情况下; 复杂密码+普通用户ssh登录

更多更安全的方式是密钥认证方式远程登录

关闭ssh的相关配置,可以看之前的文章,这主要说一下密钥:

[root@centos-1 ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:22lBLeGlcETtgsGzCXLmnEfaxRW8OFv7elmOMKK8Y50 root@centos-1
The key's randomart image is:
+---[RSA 2048]----+
|       ..+=++.   |
|    . + =+o=o    |
|     * * B=o..   |
|      = *.+.+    |
|       .S .= .   |
|         ooo+   .|
|       ..o+o + = |
|        =.E   = .|
|       ..o  .o   |
+----[SHA256]-----+
[root@centos-1 ~]# 
[root@centos-1 ~]# 
[root@centos-1 ~]# 

本地查看/root/.ssh/目录内容:

[root@centos-1 ~]# ll /root/.ssh/
total 8
-rw-------. 1 root root 1675 Sep  4 17:41 id_rsa
-rw-r--r--. 1 root root  395 Sep  4 17:41 id_rsa.pub

可见一个一个公钥一个私钥,将私钥保存到本地,将公钥留在服务器

可以选择手动拷贝id_rsa.pub到目标服务器,但是需要修改文件权限和文件名称,较为麻烦

这采用ssh-copy-id的方式:

[root@centos-1 ~]# ssh-copy-id root@192.168.100.11
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.100.11 (192.168.100.11)' can't be established.
ECDSA key fingerprint is SHA256:KsOwCvKAjfVJs98XmSgano8tBdC2LxJ+EqRaLtPEeiA.
ECDSA key fingerprint is MD5:2c:c7:25:16:f2:7a:8a:4a:21:ef:88:d0:0c:d1:e5:5c.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.100.11's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.100.11'"
and check to make sure that only the key(s) you wanted were added.

[root@centos-1 ~]# 
[root@centos-1 ~]# 
[root@centos-1 .ssh]# ll
total 8
-rw-------. 1 root root 395 Sep  4 17:41 authorized_keys
-rw-r--r--. 1 root root 176 Sep  4 17:41 known_hosts

重启服务,配置生效。

另外,请关注此目录/etc/ssh/sshd_config.d下的文件配置会覆盖/etc/ssh/sshd_config中的配置。

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或者给予支持!