【运维】Linux 常用命令整理(一)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/keylion_/article/details/86632787

内容:用户管理、解压缩、文件权限、YUM仓库配置、光盘镜像挂载、服务自启、网络静态IP配置


1、用户管理
    用户密码修改
    非交互式:

[root@localhost ~]# echo '123456' | passwd --stdin root

用户uID修改
 

[root@localhost ~]# id tom
uid=1000(tom) gid=1000(tom) 组=1000(tom)
[root@localhost ~]# usermod -u 1001 tom
[root@localhost ~]# id tom
uid=1001(tom) gid=1000(tom) 组=1000(tom)
[root@localhost ~]# usermod -g 1001 tom
usermod:“1001”组不存在
[root@localhost ~]# id root
uid=0(root) gid=0(root) 组=0(root)
[root@localhost ~]# usermod -u 0 tom
usermod:UID “0”已经存在

2、组管理

[root@localhost ~]# groupadd jerry
[root@localhost ~]# usermod -g jerry tom
[root@localhost ~]# id tom
uid=1001(tom) gid=1001(jerry) 组=1001(jerry),1000(tom)

tail 从末行查看
head 从首行查看

[root@localhost ~]# grep root /etc/passwd


3、特殊权限(权限继承)

[root@localhost ~]# mkdir /data
[root@localhost ~]# ls -ld /data
drwxr-xr-x. 2 root root 6 8月  21 09:42 /data


    修改目录属主

[root@localhost ~]# chown tom /data/
[root@localhost ~]# ls -ld /data
drwxr-xr-x. 2 tom root 6 8月  21 09:42 /data
[tom@localhost ~]$ exit


    增加SGID权限
 

[root@localhost ~]# chmod g+s /data/
[root@localhost ~]# ls -ld /data
drwxr-sr-x. 2 tom root 21 8月  21 09:45 /data
[root@localhost ~]# su - tom
上一次登录:二 8月 21 09:45:40 CST 2018pts/1 上
[tom@localhost ~]$ touch /data/jerry.txt
[tom@localhost ~]$ ls -l /data/jerry.txt
-rw-r--r--. 1 tom root 0 8月  21 09:47 /data/jerry.txt
[tom@localhost ~]$
\\10.8.48.252

4、打包压缩 j
 

[root@localhost ~]# tar zcf etc.tar.gz /etc/
   解压缩 可以不指定压缩方式
   解压到当前目录
[root@localhost ~]# tar xf etc.tar.gz
   解压到指定目录
[root@localhost ~]# tar xf etc.tar.gz -C /data/
[root@localhost ~]# ls /data/

5、zip压缩
 

[root@localhost ~]# zip anaconda-ks.zip anaconda-ks.cfg
   zip解压缩到指定目录
[root@localhost ~]# unzip anaconda-ks.zip -d /data/

6、计划任务
 

root@localhost ~]# crontab -l
23 14 * * *  /bin/echo hiya
0/5 0 * * 1-5 /bin/backup-db.sh
   编辑指定用户的计划任务
[root@localhost ~]# crontab -e -u tom
[root@localhost ~]# crontab -l -u tom
* * * * * /bin/echo tom

7、光盘挂载
 

[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
[root@localhost ~]# mount | grep mnt

8、YUM 仓库配置

[root@localhost ~]# yum-config-manager --add  file:///mnt/cdrom/
[root@localhost ~]# rm -rf /etc/yum.repos.d/CentOS-*
[root@localhost ~]# ls /etc/yum.repos.d/
[root@localhost ~]# vim  /etc/yum.repos.d/mnt_cdrom_.repo
[mnt_cdrom_]                #仓库标签
name=added from: file:///mnt/cdrom/    #仓库名称
baseurl=file:///mnt/cdrom/        #仓库位置
enabled=1                #是否启用仓库
gpgcheck=0                #是否启用gpg检查

[root@localhost ~]# yum clean all    #清空缓存
[root@localhost ~]# yum repolist    #重新生成仓库列表 3831


    
    使用YUM仓库安装httpd
 

[root@localhost ~]# yum -y  install httpd
                remove/reinstall/list
[root@localhost ~]# yum provides */httpd.conf
[root@localhost ~]# yum list | grep httpd

    重启httpd服务

[root@localhost ~]# systemctl restart httpd


    添加到开机启动

[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# firefox 127.0.0.1 &


9、网络配置
   配置ip

[root@localhost ~]# nmcli connection modify ens33 ipv4.addresses 192.168.123.100/24


   开机激活网卡

[root@localhost ~]# nmcli connection modify ens33 connection.autoconnect yes


   激活网卡
 

[root@localhost ~]# nmcli connection up ens33
   在真机cmd中 ping 192.168.123.100


10、添加防火墙规则,从真机访问网站
 

[root@localhost ~]# firewall-cmd --permanent --add-service=http
success
[root@localhost ~]# firewall-cmd --reload

猜你喜欢

转载自blog.csdn.net/keylion_/article/details/86632787