• linux加密安全和时间同步


    sudo实现授权
    添加
    vim /etc/sudoers
    luo ALL=(root) /usr/bin/mount /deb/cdrom /mnt/

    test ALL=(root:ALL) ALL 在所有主机上 提权为root用户, 可以执行所有命令
    户"test"被授权以"root"用户身份在任意主机上执行任意命令

    切换luo用户使用
    sudo mount /dev/cdrom /mnt

    %sudo ALL=(ALL:ALL) ALL
    %sudo 表示该规则适用于sudo用户组中的所有成员。
    ALL=(ALL:ALL) 表示可以在任何主机上,以任何用户身份来执行sudo命令
    第一个ALL表示允许sudo的用户在任何主机上执行命令。
    (ALL:ALL) 表示用户可以以任何用户和组的身份来执行命令。
    第二个ALL表示允许sudo的用户以任何命令。
    总之,%sudo ALL=(ALL:ALL) ALL 允许sudo用户组中的任何成员在任何主机上使用sudo命令以任何用户和组的身份来执行任何命令

    PAM认证

    模块路径
    ubuntu 路径 /usr/lib/x86_64-linux-gnu/security/
    rocky /usr/lib64/security

    /etc/pam.d/ 服务(比如sshd)调用模块的配置文件目录
    ls /etc/security/ 复杂模块的专有配置文件目录

    创建文件后用户不能登录
    vi /etc/nologin
    因为sshd服务启用了pam_nologin.so模块
    vi /etc/pam.d/sshd
    sshd:account required pam_nologin.so

    资源限制模块
    pam_limits.so

    永久()limits配置文件
    vim /etc/security/limits.conf

    • soft nofile 65535
    • hard nofile 65535
      @monitor hard nofile 65535 @代表组

    pgrep -u zabbix |wc -l 查看用户打开的进程数

    ulimit  -a
    real-time non-blocking time  (microseconds, -R) unlimited
    core file size              (blocks, -c) 0
    data seg size               (kbytes, -d) unlimited
    scheduling priority                 (-e) 0
    file size                   (blocks, -f) unlimited
    pending signals                     (-i) 8440
    max locked memory           (kbytes, -l) 284580
    max memory size             (kbytes, -m) unlimited
    open files                          (-n) 1024
    pipe size                (512 bytes, -p) 8
    POSIX message queues         (bytes, -q) 819200
    real-time priority                  (-r) 0
    stack size                  (kbytes, -s) 8192
    cpu time                   (seconds, -t) unlimited
    max user processes                  (-u) 8440
    virtual memory              (kbytes, -v) unlimited
    file locks                          (-x) unlimited
    
    
    `ulimit -a` 命令用于显示当前用户的资源限制,即操作系统对用户进程使用各种资源的限制。
    
    下面是对输出结果的解释:
    
    - `real-time non-blocking time (microseconds, -R)`: 实时非阻塞时间,表示在实时调度策略下进程的非阻塞时间限制,该值为 "unlimited" 表示没有限制。
    - `core file size (blocks, -c)`: 核心文件大小限制,表示允许生成的核心转储文件的最大大小,0 表示禁止生成核心文件。
    - `data seg size (kbytes, -d)`: 数据段大小限制,表示进程可以分配的数据段的最大大小,"unlimited" 表示没有限制。
    - `scheduling priority (-e)`: 调度优先级,数值越低优先级越高。
    - `file size (blocks, -f)`: 文件大小限制,表示进程可以创建的文件的最大大小,"unlimited" 表示没有限制。
    - `pending signals (-i)`: 待处理的信号数量限制,表示进程队列中待处理的信号的最大数量。
    - `max locked memory (kbytes, -l)`: 锁定内存的大小限制,表示进程可以锁定的最大内存大小。
    - `max memory size (kbytes, -m)`: 最大内存大小限制,表示进程可以使用的最大内存大小,"unlimited" 表示没有限制。
    - `open files (-n)`: 打开文件的数量限制,表示进程可以同时打开的文件数量上限。
    - `pipe size (512 bytes, -p)`: 管道大小限制,表示管道缓冲区的最大字节数。
    - `POSIX message queues (bytes, -q)`: POSIX消息队列大小限制,表示进程可以创建的POSIX消息队列的最大大小。
    - `real-time priority (-r)`: 实时优先级,数值越低优先级越高。
    - `stack size (kbytes, -s)`: 栈大小限制,表示进程栈的最大大小。
    - `cpu time (seconds, -t)`: CPU时间限制,表示进程可以使用的最大CPU时间,"unlimited" 表示没有限制。
    - `max user processes (-u)`: 最大用户进程数限制,表示用户可以同时运行的进程数量上限。
    - `virtual memory (kbytes, -v)`: 虚拟内存大小限制,表示进程可以使用的最大虚拟内存大小,"unlimited" 表示没有限制。
    - `file locks (-x)`: 文件锁数量限制,表示进程可以同时持有的文件锁的数量上限。
    
    注意,输出结果中的 "unlimited" 表示没有明确的限制,即对应的资源在系统中是无限的。其他数值表示该资源对应的限制值。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    通过service 文件启动服务启动要限制还要在service文件中设置,只在limit.conf 中限制不生效

    使用google MFA验证功能

    ubuntu安装google-authenticator
    apt install libpam-google-authenticator -y

    rocky安装 :ip 192.168.74.132
    yum install -y google-authenticator

    在这里插入图片描述

    按y
    服务google连接

    修改ssh和模块配置

    sed -i '1a\auth       required     pam_google_authenticator.so' /etc/pam.d/sshd
    sed -i 's/.*ChallengeResponseAuthentication.*/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config
    
    #重启SSH服务
    service sshd restart
    
    • 1
    • 2
    • 3
    • 4
    • 5

    其他机器测试ssh远程

    root@server:/etc/security/limits.d# ssh 192.168.74.132
    (root@192.168.74.132) Verification code: 
    (root@192.168.74.132) Password: 
    Activate the web console with: systemctl enable --now cockpit.socket
    
    Last failed login: Wed Oct 18 01:05:39 CST 2023 from 192.168.74.80 on ssh:notty
    There were 2 failed login attempts since the last successful login.
    Last login: Wed Oct 18 01:00:20 2023 from 192.168.74.1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    在这里插入图片描述

    时间同步

    配置服务端

    apt install chrony -y

    vim /etc/chrony.conf
    server   ntp.aliyun.com  iburst #iburst 加快同步速度
    server   slb.time.edu.cm  iburst
    allow 0.0.0.0/0   
    #local stratum 10   
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    systemctl restart chronyd.service

    [root@rocky8 ~]# chronyc
    chrony version 4.2
    Copyright © 1997-2003, 2007, 2009-2021 Richard P. Curnow and others
    chrony comes with ABSOLUTELY NO WARRANTY. This is free software, and
    you are welcome to redistribute it under certain conditions. See the
    GNU General Public License version 2 for details.

    chronyc> sources -v

    [root@rocky8 ~]# chronyc sources -v
    
      .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
     / .- Source state '*' = current best, '+' = combined, '-' = not combined,
    | /             'x' = may be in error, '~' = too variable, '?' = unusable.
    ||                                                 .- xxxx [ yyyy ] +/- zzzz
    ||      Reachability register (octal) -.           |  xxxx = adjusted offset,
    ||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
    ||                                \     |          |  zzzz = estimated error.
    ||                                 |    |           \
    MS Name/IP address         Stratum Poll Reach LastRx Last sample               
    ===============================================================================
    ^- 203.107.6.88                  2   6    17    19   -738us[  -11us] +/-   39ms
    ^* 120.25.115.20                 2   6    17    14   +408us[+1033us] +/- 6971us
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    配置客户端

    安装chrony

    修改配置文件,添加chrony服务器
    server 192.168.74.132 
    
    
    
    MS Name/IP address         Stratum Poll Reach LastRx Last sample               
    ===============================================================================
    ^* 192.168.74.132                3   6   367    42  -6262us[-8180us] +/-   59ms
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 相关阅读:
    Coursera自动驾驶1.5——纵向控制
    Unity使用Remote直接在手机上调试游戏
    122页6万字消防大数据平台建设方案
    Xilinx FPGA 7系列 GTX/GTH Transceivers (2)--IBERT
    手势识别易语言代码
    快速排序(非递归)和归并排序
    u盘损坏如何恢复数据?u盘恢复数据,超好用的几个方法!
    操作系统专项练习
    04设计模式-建造型模式-工厂模式
    Vue开发工具后浏览器报错
  • 原文地址:https://blog.csdn.net/m0_37749659/article/details/133894381