与Linux的第五夜

以下内容均学习于51CTO老男孩

SecureCcRT批量部署:

  1. 多个会话在同一标签页中打开;
  2. 查看→交谈窗口→最下面空白处右键→发送交互到所有会话(send chat to all tabs)
  3. 在空白处执行的命令将会在所有会话执行;

【cat /etc/redhat-release】查看系统版本

【uname -r】查看内核版本

【uname -m】查看系统位数

【hostname】查看主机名

【uname】print system information

  • -r
  • -m
  • -n→查看主机名hostname
  • -a→查看所有

【useradd】

[root@wind ~]# useradd zd
[root@wind ~]# tail -1 /etc/passwd
zd:x:500:500::/home/zd:/bin/bash
[root@wind ~]# tail -1 /etc/group
zd:x:500:
[root@wind ~]# tail -1 /etc/shadow
zd:!!:18265:0:99999:7:::
[root@wind ~]# passwd zd
Changing password for user zd.
New password: 
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.

【whoami】

[root@wind ~]# whoami
root
[zd@wind ~]$ whoami
zd

[root@wind ~]

  • root用户名
  • wind主机名
  • ~当前路径
  • 受PS1控制

【echo $PS1】

[zd@wind ~]$ echo $PS1
[\u@\h \W]\$
[zd@wind ~]$PS1="[\u@\h \W \t]$"
[zd@wind ~ 20:58:21]$

【su】切换用户

  • 【su - user】环境变量也更改
  • 【su user】环境变量不变,所以一般不用
[zd@wind ~]$ su root
Password: 
[root@wind zd]# env|grep zd
USER=zd
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/zd/bin
MAIL=/var/spool/mail/zd
PWD=/home/zd
LOGNAME=zd
[root@wind zd]# pwd
/home/zd
[root@wind zd]# 

普通用户到root需要root密码,但是反之则不需要密码。

系统优化及安全设置:

关闭SELinux(Security-Enhanced Linux)

  关闭方式: 

  1)修改配置文件,使SELinux永久失效:

    1.修改/etc/selinux/config文件中的SELINUX=enforcing为SELINUX=disabled;

    2.修改过程遵循修改前备份,修改后检查的原则;

    3.修改了配置文件必须重启服务器才会生效,但是生产场景不允许重启服务器,

[root@wind ~]# cp /etc/selinux/config /tmp
[root@wind ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
[root@wind ~]# grep =disabled /etc/selinux/config
SELINUX=disabled

  2)【setenforce 0】临时生效:1是enforcing 0是permissive

[root@wind ~]# getenforce
Enforcing
[root@wind ~]# setenforce
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@wind ~]# setenforce 0
[root@wind ~]# getenforce
Permissive

  3)执行1)2)完成不用重启服务器的生效模式;

设定运行级别

在/etc/inittab文件里,查看当前级别【runlevel】

[root@wind ~]# runlevel
N 3

【init 0123456】切换级别;默认是3;

例如init 5等价于startx,切换桌面环境,需要桌面环境的包;

精简开机系统启动

  重要的开机自启动服务:

  •   sshd,远程连接服务器时需要用到这个服务程序;
  •        rsyslog,是操作系统提供的一种机制,系统的守护程序通常会使用rsyslog将各种信息写到各个系统日志文件中;
    • cat /var/log/massages
  •        network,若想激活或关闭某个网卡
  •        crond,该服务用于周期性的执行系统及用户配置的任务计划,有要周期性执行的任务要开启,生产必用;
  •        sysstat,是监测系统性能的一组工具
    • iostat,CPU使用率,硬盘吞吐效率
    • mpstat,提供与单个或者多个处理器相关的数据
    • sar,收集、报告并存储系统的活跃的信息

  修改开机自启动:

  1)setup→System services

  2)  ntsysv等价于1)

  3)chkconfig --list|grep 3:on找到运行级别为3的开启的服务,如果要关闭atd服务chkconfig --level 3 atd off

[root@wind ~]# chkconfig --list atd
atd             0:off   1:off   2:off   3:on    4:on    5:on    6:off
[root@wind ~]# chkconfig --level 3 atd off   
[root@wind ~]# chkconfig --list atd
atd             0:off   1:off   2:off   3:off   4:on    5:on    6:off
[root@wind ~]# 
[root@wind ~]# for name in `chkconfig --list|awk '{print $1}'|grep -Ev "sshd|network|rsyslog|croud|sysstat"`;do chkconfig $name off;done
[root@wind ~]# chkconfig --list|grep 3:on|awk '{print $1}'|grep -Ev "sshd|network|rsyslog|crond|sysstat"|sed -r 's#(.*)#chkconfig \1 off#g'
chkconfig atd off
chkconfig ntpd off
[root@wind ~]# chkconfig --list|grep 3:on|awk '{print $1}'|grep -Ev "sshd|network|rsyslog|crond|sysstat"|sed -r 's#(.*)#chkconfig \1 off#g'|bash
[root@wind ~]# chkconfig --list|grep 3:on
crond           0:off   1:off   2:off   3:on    4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
rsyslog         0:off   1:off   2:on    3:on    4:on    5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
sysstat         0:off   1:on    2:on    3:on    4:on    5:on    6:off

【sed】

[root@wind ~]# sed -r 's#(.*)# \# \1#g' okra.txt
 # ok,
 # i am
 # a stay up
 # man, so...
 # end.

【awk】

[root@wind ~]# chkconfig --list|grep 3:on|awk '{print $1}'|grep -Ev "sshd|network|rsyslog|crond|sysstat"|awk '{print "chkconfig " $1 "off"}'|bash

RHEL7 中使用了firewalld代替了原来的iptables,操作设置和原来有点不同:

查看防火墙状态:systemctl status firewalld

启动防火墙:systemctl start firewalld

停止防火墙:systemctl stop firewalld

Print certain system information.  With no OPTION, same as -s.
       -a, --all              print  all information, in the following order, except omit -p              and -i if unknown:
       -s, --kernel-name              print the kernel name
       -n, --nodename              print the network node hostname
       -r, --kernel-release              print the kernel release

猜你喜欢

转载自www.cnblogs.com/okra/p/12150975.html
今日推荐