技术学无止尽

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 107|回复: 0

centos7 安全升级命令 centos7更新命令

[复制链接]

297

主题

301

帖子

1659

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1659
发表于 2024-10-11 21:31:07 | 显示全部楼层 |阅读模式
查看所有网卡IP地址——ip addr

启动防火墙——systemctl start firewalld.service

停止防火墙——systemctl stop firewalld.service

禁止防火墙开机启动——systemctl disable firewalld.service

列出正在运行的服务状态——systemctl

启动一个服务——systemctl start postfix.service

关闭一个服务——systemctl stop postfix.service

重启一个服务:——systemctl restart postfix.service

显示一个服务的状态——systemctl status postfix.service

在开机时启用一个服务——systemctl enable postfix.service

在开机时禁用一个服务——systemctl disable postfix.service

查看服务是否开机启动——systemctl is-enabled postfix.service;echo $?

查看已启动的服务列表——systemctl list-unit-files|grep enabled

设置系统默认启动运行级别3——ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

设置系统默认启动运行级别5——ln -sf/lib/systemd/system/graphical.target/etc/systemd/system/default.target

-----------------------------------------------工作常用命令 end----------------------------------------

----------------------------------------------服务管理命令的变化 begin----------------------------------------

CentOS 7 (RHEL 7)带来了新的服务管理命令,为了保持兼容原有的命令仍可以使用,以下是新旧命令的对照。

启动、停止、重启、重载、检查服务:
6: service httpd start|stop|restart|reload|status
7: systemctl start|stop|restart|reload|status httpd.service

允许、禁止服务自启动:
6: chkconfig httpd on|off
7: system enable|disable httpd.service

列出服务:
6: chkconfig –list
7: systemctl list-unit-files –type=service 或 ls /etc/systemd/system/*.wants/

添加服务:
6: chkconfig httpd –add
7: systemctl daemon-reload
----------------------------------------------服务管理命令的变化 begin----------------------------------------
----------------------------------------------centos 7服务命令总结 begin----------------------------------------

隐藏文件: 系统文件  不能乱动   
ls -a
ls  /
ls -l    --long

权限(ugo)  引用计数  所有者  所属组  文件大小   最后修改时间  文件名称
ls -l   /

- d  l   管道文件  套子接  
rw- r-- r--
只有当需要运行的时候 ,是个脚本   才给予执行权限
ls -ld /etc
查看目录本身的详细信息
文件的id号
ls -i  /etc
=========
mkdir /tmp/xiaoming
mkdir -p /tmp/japan/boduo
mkdir /tmp/janpan/ce /tmp/janpan/ed
cd /tmp/janpan
cd /etc
pwd  当前目录

rmdir /tmp/janpan/dd  只能删除空目录
rm -rf file  

cp /tmp/dd /root
cp -r /tmp/janpan /root  -r 复制目录
cp -r /tmp/janpan /root/jap18  复制同时改名
cp /2.txt /a.txt /tmp
cp -p /2.txt /a.txt /tmp 文件时间不会改变

ctrl+l  清屏

mv /tmp/janpan/cj /root  剪切
mv /tmp/janpan/lz /root/ns
mv 23 45  
================
touch aa
touch "aa bb"


cat file
cat -n file  行号

tac file

more file  q退出   , 回车  一行 ,  空格  翻页

less file   搜索 /nologin    n 下一个  


head -n 7 /etc/passwd   head file 默认前10行

tail  -n 7 file        tail file ..

=================
ln -s /etc/issue /tmp/issue.soft
ln /etc/issue /tmp/issue.hard

硬链接同步更新
=======
文件权限
chmod ugoa +-= rwx file/d

chmod u+x,g+w 2.txt
chmod g=rwx 2.txt

chmod 640 2.txt

chmod 777 /tmp/a   a目录下的权限不随之改变

chmod -R 777 /tmp/a  改变目录下的所有权限

改变文件的所有者  只有管理员可以做
chown root ab   更改所有者

什么时候改变     
当文件本身所有者有业务出差时 ,交予其他人继续完成

groupadd test  更改组
chgrp test aa

=====================
find 范围  条件  ? 单个字符   *  多个字符

find / -name init?
find / -iname init  忽略大小写


find / -size +204800  大于100M的文件 1数据块 =512字节 0.5k 100m=102400kb=204800
find /home -user cxl   查找所有者为cxl的文件

find / -cmin -5   change  文件属性  
find / -amin -5   access  访问时间  
find / -mmin -5   modify  文件内容 5分钟以前


find /etc -name init* -a -type f/d/l

find /etc -name inittab -exec ls -l {} \;注意空格


find /etc -name init* -a -type f -ok  rm {} \;   
-0  或者

ls -i  

find . -inum 31531 -exec rm {} \;


=locate  文件资料库
  locate inittab  命令未找到
yum -y install mlocate
[ root @localhost  tmp]# locate inittab   
locate: can not stat () `/var/lib/mlocate/mlocate.db': 没有那个文件或目录
安装成功了,现在使用 updatedb 命令来创建locate命令依赖的数据库。
[ root @localhost  tmp]# updatedb
这样就OK了



/var/lib/mlocate/mlocate.db   定期更新   
也可以手动更新
updatedb

touch abc
locate abc  找不到
updatedb
locate abc  找到了

缺点:找不到tmp 下面的文件

locate -i file  不区分大小写

=which  查找命名所在的目录  别名
  which ls/mkdir

=whereis 路径 、 手册
  
whereis ls / rm  


=grep   -iv 字符串 目录 【 -i 不区分大小写 -v 排除指定字符串】


grep -i mysql /install.log

grep -v ^#  /etc/inittab

===================================
帮助命令
man ls  
man rm  

/abc 搜索  q   enter 一行  空格 /翻页   

man  passwd 1 命令的帮助  5 配置文件的帮助

whereis passwd
man passwd   

whatis ls
apropos /etc/inittab

touch --help
ls --help
rm --help

help umask

============
用户管理

useradd yangmi
passwd yangmmi


who  
w   tty 本地终端   pts 远程终端
uptime


============
压缩

gzip abc   abc.gz
gunzip abc.gz  
只可以压缩文件  不可以压缩目录

tar  打包  目录
tar -cvf janpan.tar janpan
gzip janpan.tar  =>janpan.tar.gz
---------
tar -zcvf janpan.tar.gz janpan  压缩  z 压缩
tar -zxvf janpan.tar.gz         解压  z 解压  x 解包
---------
zip
yum install zip

zip abc.zip abc

zip -r janpan.zip janpan

unzip abc.zip
------
bzip2 -k abc  保留源文件
tar -cjf janpan.tar.bz2 janpan
bunzip2 -k abc.bz2
tar -xjf janpan.tar.bz2
==========================
网络命令

wirte cxl
wall lingzhliing you l

ip addr eno16777736 192.168.124.127

last  
lastlog


traceroute   www.sina.com.cn
netstat -tlun  查看本机已开启了哪些端口

tcp 可以接受访问   所以有监听



netstat -an  查看正在连接的程序
netstat -rn  查看本机路由表


挂载光盘
设置  设备状态  已连接  要打勾  不然连接不通
dev/cdrom
mkdir /mnt/cdrom
mount -t iso9660 /dev/sr0 /mnt/cdrom
cd /mnt/cdrom

umount /dev/cdrom   卸载
============================
vim


命令模式
set nu

a :在光标所在字符后插入
A :在光标所在行尾插入
i :在光标所在字符前插入
I :在光标所在行行首插入
o :在光标下插入新行
O :在光标上插入新行



:set nu   设置行号
:set nonu 取消行号

gg 到第一行
G  到最后一行

nG 到第n行
:n 到第n行

$ :行尾  
0 :行首

x:删除光标所在处字符
nx:删除光标所在处后n个字符
dd:删除光标所在行
dG:删除光标所在行到文件末尾内容
D:删除光标所在处到行尾内容
:n1,n2d ps: :3,5d 删除3到5行   


yy 复制当前行
nyy 复制当前行以下n行
dd  剪切当前行
ndd 剪切当前行以下n行
p 、P 粘贴在当前光标所在行下或行上


r :替换
R :替换
u :取消


:set ic 忽略大小写

/string            搜索
n                  搜索指定字符串的下一个出现的位置
:%s/old/new/g      全文替换指定字符串
:n1,n2s/old/new/g  在一定范围内替换指定字符串

:%s/old/new/c   会询问是否替换

w 保存修改
wq 保存退出
ZZ 保存退出
q! 不保存退出
wq! 保存退出

:r !命令  在光标所在处下面导入执行结果


:n1,n2s/^/#/g    替换
:n1,n2s/^#//g
:n1,n2s/^/\/\//g

替换  在做编辑的时候  把长的文字用别名表示,输入后又会变为原来的内容
ab my   cxlhk772@163.com   

==================================

软件包  

  源码包  脚本安装包

  二进制包 (rpm,系统默认包)



rpm  

rpm  -ivh file  安装





rpm -ivh 包全名  安装

rpm -Uvh 包全名  升级

rpm -e 包名 卸载

rpm -q 包名  查询包

rpm -qa      查询所有包

rpm -qi 包名  包的详细信息

rpm -qip 包全名  查看未安装包的信息

rpm -ql 包名    查看安装路径

==========

yum list  查询所有可用软件包

yum search 关键字

yum -y install 包名    包全名概念只在rpm中存在

yum -y install gcc c语言编辑器   所有源码包都需要c的支持

yum -y update 包名   升级

yum -y remove 包名   卸载

yum -y update 升级所有  包括内核   危险 慎用



yum grouplist  列出所有可用的软件组列表

yum groupinstall 软件组名

yum groupremove  软件组名

==本地光盘yum搭建






测试

yum list       ==>c6

==

rpm -q httpd

rpm -ql httpd

源码安装

httpd-2.4.12

du -sh   httpd-2.4.12

下载httpd-2.4.12.tar.gz

安装httpd   ?

========================

7. 用户 用户组

普通用户变成管理员,只需要在/etc/passwd把第3个字段改为0即可!

用户密码存放在/etc/shadow中

普通用户的id在500到65535之间

shadow

/etc/shadow

/etc/group 组信息

默认创建用户的时候  组名跟用户名一样的

/etc/gshadow

组中  会有组长   给组长一个密码  来管理其他人

windows是把用户添加到管理员组   是改了组id

mail

/var/spool/mail/用户名/    只是客户端  没有服务器

/etc/skel  如果在此文件下创建文件  则每次增加用户时 都会生成该文件

ps:   skel  / a b

useradd trr  

cd /home  

a b

==========

grep sc /etc/passwd

grep sc /etc/shadow

grep sc /etc/group

grep sc /etc/gshadow



加密成功

/etc/shadow 密码前会有!

解锁成功 会消失 即可登陆

删除用户   

userdel  ttr

groupadd -g gid  test

groupmod -g gid  -n newg oldg

groupdel    组名



删除主组时,先删除用户 userdel -r  user groupdel tg

gpasswd -a user1 tg

gpasswd -d lamp1 tg

gpasswd 操作的是附加用户

============================

10  .   shell

history

alias 别名='xx'

unalias 别名

输出重定向

ls  > ab  覆盖

ls  >> ab 追加

lst  2>>ab   错误命令输出

ls >> bc 2>&1

datag &>>bc

ls &>/dev/null

ls >> de 2>>ef    正确命令输出到de   错误输出到ef

==wc

-c 统计字节  -w 统计单词数  -l  统计行数

wc <anaconda-ks.cfg

60 130 1531

60 行   130单词   1531字符





----------------------------------------------centos 7服务命令总结 begin--------------------------------------





回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-5-4 18:23 , Processed in 0.047800 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表