RHSCA学习二(ssh配置和保护,使用密钥登录ssh)redhat linux日志管理,同步系统时钟NTP

RHCSA 认证学习笔记二

配置和保护SSH
TCP 22 端口
加密传输数据,用来替代telnet tcp 23 端口
SSH协议提供两种用户认证方式
➢ 基于口令的安全认证
• 与telnet类似,提供正确的用户口令后可以登录远程服务器
➢ 基于密钥的安全认证
• 使用公钥和私钥对的方式对用户进行认证
OpenSSH的服务程序名称是sshd
⚫ sshd服务程序缺省状态为自动启动
⚫ sshd服务的启动与停止
systemctl start sshd 启动服务
stop 停止服务
restart 重启服务
reload 重新加载服务配置文件
status 查询服务启动当前状态
enable 使得服务开机自动启动
disable 使得服务开机不启
systemctl is-active sshd 查询服务是否启动
systemctl is-enabled sshd 查询服务是否开机启动

配置目录
➢ OpenSSH服务器和客户机的所有配置文件都保存在同一目录中
/etc/ssh/
⚫ 服务器配置文件
SSH服务器的配置文件是sshd_config
/etc/ssh/sshd_config

⚫ 客户机配置文件
SSH客户程序的配置文件是ssh_config
/etc/ssh/ssh_config

连接ssh
[root@redhatone ~]# ssh [email protected]
The authenticity of host ‘192.168.184.129 (192.168.184.129)’ can’t be established.
ECDSA key fingerprint is SHA256:4UD/tblagmxyXh0SVafWqBn/Uq34ibOZAJF+ugqzGvs.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.184.129’ (ECDSA) to the list of known hosts.
[email protected]’s password:
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sun Aug 2 00:29:14 2020
[root@redhatwo ~]#

上传下载文件(scp)
[root@redhatone ~]# scp test1 [email protected]:/
[email protected]’s password:
test1 100% 0 0.0KB/s 00:00
[root@redhatone ~]#

[root@redhatwo /]# ls
bin dev home lib64 mnt proc run srv test1 usr
boot etc lib media opt root sbin sys tmp var
[root@redhatwo /]#
上传下载目录 (scp -r) 后面我还是再详细解释,这里主要是用到了一点点的 csp知识


使用密钥登录ssh
客户端:生成一对密钥
ssh-keygen 生成密钥
[root@redhatone ~]# ssh-key
ssh-keygen ssh-keyscan
[root@redhatone ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): // 密钥保存路径
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:UdJ34rO66sQJdU7+ZRNjn4OXE4/Nc71QR7HKW8J17Mw root@redhatone
The key’s randomart image is:
±–[RSA 2048]----+
| … .o|
| o. o .o.|
| o oo o+=+|
| . * =.=@O|
| . S o X=OE|
| o . …o*.*|
| + … . |
| . . |
| .o… |
±—[SHA256]-----+
[root@redhatone ~]#
上传公钥到服务器指定的账户
[root@redhatone ~]# ssh-copy-id [email protected]
/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
[email protected]’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘[email protected]’”
and check to make sure that only the key(s) you wanted were added.

[root@redhatone ~]#
这里呢,当然我们也可以用上面讲到的scp来实现,只需要把指定目录下的保存的公钥scp到对面的服务器的指定目录下面就可以了 其实和这里的ssh-copy-id 是一样的功能


服务器试试安全性设置
编辑:[root@redhatone ~]# vim /etc/ssh/sshd_config
1.更改指定端口 Port 22000
2.禁止root登录 PermitRootLogin no
3.禁止密码验证 PasswordAuthentication no


linux 日志管理

所有的日志触发都是有systemd-journald程序处理日志事件,然后分类发送给rsyslog程序,rsyslog程序再次分两类存储到 /var/log/ 中
messages 多数信息记录到此文件
secure 记录和身份验证相关的信息
maillog 电子邮件信息
boot.log 系统启动过程信息
cron 任务计划信息
lastlog 用户登陆信息

cat
tail -f secure -f 监控日志
more xxx 分屏显示
less xxx 默认不退出显示,按q键退出
在redhatone上开启日志接受功能(日志服务器统一接收所有被管理的日志消息)
编辑 vim /etc/rsyslog.conf
启用UDP514端口接收,TCP启动类似
在这里插入图片描述
测试:重启rsyslog服务 ,这里需要关闭防火墙
systemctl restart rsyslog.service
systemctl stop firewawlld.service
在redhattwo 上使用logger命令测试日志消息
[root@redhatwo /]# logger -n 192.168.184.128 -d -P 514 111111111111155555555555555554444444444
[root@redhatwo /]#
这里是P 这个参数我一直弄错,今天我就说嘛 怎么老是提示我参数问题出错,大家做的时候记得参数一定大写的P
在这里插入图片描述
客户端将所有的日志消息都发送到服务器上面去
编辑 /etc/rsyslog.conf
在这里插入图片描述

ournalctl 查看日志
journalctl
journalctl -n 10
journalctl -p err
journalctl -f 和tail -f一个效果 监控日志


同步系统时钟 NTP

所用软件chronyd
vim /etc/chrony.conf
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server 172.25.254.250 iburst
时钟服务器172.25.254.254 iburst加速同步
systemctl restart chronyd
timedatectl 改时区,改时间
timedatectl list-timezones *************查看时区
timedatectl set-time 20:00:00 *************配置时间

猜你喜欢

转载自blog.csdn.net/qq_41837249/article/details/107747063