zoukankan      html  css  js  c++  java
  • 004---Linux系统设置

    Linux版本相关命令

    • 查看系统版本:cat /etc/redhat-release
    • 查看系统内核版本以及位数:uname -r
    [root@hostname1 ~]# cat /etc/redhat-release 
    CentOS Linux release 7.6.1810 (Core) 
    [root@hostname1 ~]# uname -r
    3.10.0-957.el7.x86_64
    

    PS1

    变量名,系统变量一般都是大写。

    [root@hostname1 ~]# echo $PS1
    [u@h W]$
    [root@hostname1 ~]# # u-->当前用户名:whoami
    [root@hostname1 ~]# # h-->当前主机名:hostname
    [root@hostname1 ~]# # W-->当前目录:pwd
    [root@hostname1 ~]# whoami
    root
    [root@hostname1 ~]# hostname
    hostname1
    [root@hostname1 ~]# pwd
    /root
    

    修改PS1:加时间

    [root@hostname1 ~]# PS1='[u@h W 	]$'
    [root@hostname1 ~ 20:34:51]#
    
    

    linux系统优化

    用户

    • 添加用户:useradd JiangZiYa
    • 查看用户:id JiangZiYa
    • 修改密码:passwd JiangZiYa
    • 查看当前用户:whoami
    • 切换用户:su - JiangZiYa
    • 切换root用户:su - or su - root
    • 注销用户:logout or ctrl + D
    [root@hostname1 ~]# useradd JiangZiYa
    [root@hostname1 ~]# id JiangZiYa
    uid=1000(JiangZiYa) gid=1000(JiangZiYa) groups=1000(JiangZiYa)
    [root@hostname1 ~]# id user
    id: user: no such user
    [root@hostname1 ~]# passwd JiangZiYa
    Changing password for user JiangZiYa.
    New password: 
    Retype new password: 
    passwd: all authentication tokens updated successfully.
    
    [root@hostname1 ~]# whoami
    root
    [root@hostname1 ~]# su - JiangZiYa
    Last login: Mon Feb  4 21:11:38 CST 2019 on pts/0
    [JiangZiYa@hostname1 ~]$ whoami
    JiangZiYa
    [JiangZiYa@hostname1 ~]$ su -
    Password: 
    Last login: Mon Feb  4 21:11:24 CST 2019 on pts/0
    [root@hostname1 ~]# logout
    [JiangZiYa@hostname1 ~]$ 
    
    
    

    关闭SELinux

    • 查询状态:getenforce
      • Enforcing:正在执行
      • Permissive:临时关闭,还是提示警告
      • Disabled :彻底关闭
    [JiangZiYa@hostname1 ~]$ getenforce 
    Enforcing
    
    [root@hostname1 ~]# getenforce 
    Permissive
    
    [root@hostname1 ~]# getenforce
    Disabled
    
    
    • 临时关闭:setenforce 0
    [root@hostname1 ~]# setenforce 0
    
    • 永久关闭:vim /etc/sysconfig/selinux
    SELINUX=disabled
    

    重启生效

    关闭防火墙

    • 查看防火墙状态:systemctl status firewalld or firewall-cmd --state
    [root@hostname1 ~]# systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
       Active: active (running) since Mon 2019-02-04 21:43:15 CST; 1min 50s ago
         Docs: man:firewalld(1)
     Main PID: 6308 (firewalld)
       CGroup: /system.slice/firewalld.service
               └─6308 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
    
    Feb 04 21:43:13 hostname1 systemd[1]: Starting firewalld - dynamic firewall daemon...
    Feb 04 21:43:15 hostname1 systemd[1]: Started firewalld - dynamic firewall daemon.
    
    [root@hostname1 ~]# firewall-cmd --state
    running
    
    
    
    • 临时关闭防火墙:systemctl stop firewalld
    [root@hostname1 ~]# systemctl stop firewalld
    [root@hostname1 ~]# systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
       Active: inactive (dead) since Mon 2019-02-04 21:45:58 CST; 1s ago
         Docs: man:firewalld(1)
      Process: 6308 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
     Main PID: 6308 (code=exited, status=0/SUCCESS)
    
    Feb 04 21:43:13 hostname1 systemd[1]: Starting firewalld - dynamic firewall daemon...
    Feb 04 21:43:15 hostname1 systemd[1]: Started firewalld - dynamic firewall daemon.
    Feb 04 21:45:57 hostname1 systemd[1]: Stopping firewalld - dynamic firewall daemon...
    Feb 04 21:45:58 hostname1 systemd[1]: Stopped firewalld - dynamic firewall daemon.
    [root@hostname1 ~]# 
    
    
    • 永久关闭防火墙:systemctl disable firewalld
    [root@hostname1 ~]# systemctl disable firewalld
    
    [root@hostname1 ~]# reboot
    
    Connecting to 10.0.0.128:22...
    Could not connect to '10.0.0.128' (port 22): Connection failed.
    
    Type `help' to learn how to use Xshell prompt.
    [c:~]$ 
    
    Connecting to 10.0.0.128:22...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.
    
    Last login: Mon Feb  4 21:52:23 2019 from 10.0.0.1
    [root@hostname1 ~]# systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
       Active: inactive (dead)
         Docs: man:firewalld(1)
    [root@hostname1 ~]# firewall-cmd --state
    not running
    
    • 重启防火墙:systemctl restart firewalld
  • 相关阅读:
    Bookmarks_www2
    Linux系统各发行版镜像下载(持续更新)
    tiny-rtems-src
    rtems-os-source
    OpenRCT2-ext
    PAT甲级1004题解——并查集思想改
    PAT甲级1008水题飘过
    PAT甲级1007题解——贪心
    PAT甲级1006水题飘过
    PAT甲级1005水题飘过
  • 原文地址:https://www.cnblogs.com/xjmlove/p/10351652.html
Copyright © 2011-2022 走看看