Linux的一些常用简单命令

199 阅读2分钟

linux常用命令

  1. 查看服务器系统信息
uname -a

  1. 查看服务器系统版本
cat /etc/redhat-release 

  1. 开启防火墙
systemctl start firewalld

  1. 查看防火墙状态
firewall-cmd --state 

systemctl status firewalld

  1. 关闭防火墙
 systemctl stop firewalld

  1. 重启防火墙
 firewall-cmd --reload
  1. 开放(关闭)端口
 firewall-cmd --zone=public --add-port=80/tcp --permanent   # 将80端口替换为要开放的端口

    –zone #作用域add-port=80/tcp #添加端口,格式为:端口/通讯协议
    –permanent #永久生效,没有此参数重启后失效

 firewall-cmd --remove-port=80/tcp --permanent  # 将80端口替换为要开放的端口

  1. 查询端口是否开放
 firewall-cmd --query-port=123/tcp
 yes 表示开启 no 表示关闭

  1. 查看已开放的端口列表
 firewall-cmd --list-ports  

  1. 查看已开放的端口列表
 firewall-cmd --list-ports  

  1. 添加用户
[root@localhost~]# passwd banana
Changing password for user banana.
New password:             # 输入密码
Retype new password:      # 再次输入密码
passwd: all authentication tokens updated successfully.
  1. 给用户授权,添加sudo权限
1、查找sudoers文件路径并赋予权限

1 [root@localhost~]# whereis sudoers                     # 查找sudoers文件路径
2 sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz
3 [root@localhost~]# ls -l /etc/sudoers                  # 查看权限
4 -r--r----- 1 root root 3938 Sep  6  2017 /etc/sudoers  # 只有读权限
5 [root@localhost~]# chmod -v u+w /etc/sudoers           # 赋予读写权限
6 mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)
 

2、修改sudoers文件

输入命令 vim /etc/sudoers 修改sudoers文件,添加新用户信息:

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
banana ALL=(ALL) ALL #这个是新用户

然后输入命令 wq! 保存修改。

3、收回权限

[root@localhost~]# chmod -v u-w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0640 (rw-r-----) to 0440 (r--r-----)

4、新用户登录

新建连接,使用新创建的用户登录,并进行验证,比如:

[prefma@localhost~]$ pwd
/home/banana
[prefma@localhost~]$ ls -l /etc/sudoers
-r--r----- 1 root root 3995 Oct 16 22:42 /etc/sudoers

  1. 添加docker 权限给banana用户
添加docker group:
sudo groupadd docker

将当前用户添加到docker组:
sudo gpasswd -a banana docker

重启docker服务:
sudo service docker restart
  1. 查询未使用的镜像

     docker images|grep none