Linux常用命令【持续更新ing...】

Linux常用命令

  • 文本编辑类

替换文件中^M的特殊字符

1.检查脚本中有没有^M的特殊字符
[root@zixiao-linux ~]# vim -b "脚本名称"
2.如果有, 执行sed字符替换命令
[root@zixiao-linux ~]# sed -i 's/\r//g' "脚本名称"
  • 系统设置类

免密登录

1.生成密钥
[root@zixiao-linux ~]# ssh-keygen -t rsa    
2.修改 .ssh/authorized_keys 文件,添加密钥,或者将公钥传送到远程主机host上面
     语法:ssh-copy-id [-i [identity_file]] [user@]machine
[root@zixiao-linux ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub user@server

修改ssh端口

1.修改ssh端口
vim /etc/ssh/sshd_config 
找到#Port 22 修改为自定义的端口
内容默认是被注释的,先关闭注释,再修改.保存退出(注意,修改该文件需要 root 权限)
2.重启 sshd 服务
[root@zixiao-linux ~]# service sshd restart

禁止root远程登陆

1.禁止root 远程登录修改一个文件即可,文件地址为/etc/ssh/sshd_config,修改内容为 PermitRootLogin no,
内容默认是被注释的,先关闭注释,再修改.保存退出(注意,修改该文件需要 root 权限)
2.重启 sshd 服务
[root@zixiao-linux ~]# service sshd restart

禁止密码登录,需先配置免密登录

ps:在禁用密码登录前,要先配置好免密登录,不然退出后你就上不去了.
1.编辑远程服务器上的sshd_config文件,去掉注释,并将PasswordAuthentication yes改为no
#PasswordAuthentication no
2.编辑保存完成后,重启ssh服务使得新配置生效,然后就无法使用口令来登录ssh了
[root@zixiao-linux ~]# systemctl restart sshd.service

Root用户给其他用户赋文件夹的权限

命令: chown -R 用户名 文件夹路径
[root@zixiao-linux ~]# sudo chown -R user /mnt/ssd1/dir

操作防火墙

1.停用防火墙
[root@zixiao-linux ~]# systemctl stop firewalld.service
2.查看防火墙状态
[root@zixiao-linux ~]# firewall-cmd --state
3.显示网络状态
[root@zixiao-linux ~]# netstat -lnpt
[root@zixiao-linux ~]# netstat -lnpt |grep 5672
ps:生产环境禁止关闭防火墙,只能开放端口
[root@zixiao-linux ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent   # 开放5672端口
[root@zixiao-linux ~]# firewall-cmd --zone=public --remove-port=5672/tcp --permanent  #关闭5672端口
[root@zixiao-linux ~]# firewall-cmd --reload   # 配置立即生效
4.查询端口list:
[root@zixiao-linux ~]#  firewall-cmd --list-ports
附firewall的其他命令操作
systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体.
启动: systemctl start firewalld
查看状态: systemctl status firewalld
停止: systemctl disable firewalld
禁用: systemctl stop firewalld
启动服务:systemctl start firewalld.service
关闭服务:systemctl stop firewalld.service
重启服务:systemctl restart firewalld.service
服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed
查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic

查看内核版本

1.查看当前内核版本
[root@zixiao-linux ~]# uname -a
2.检测内核版本,显示可以升级的内核
[root@zixiao-linux ~]# yum info kernel -q

CentOS 7自动卸载多余内核

1.获取到当前系统正在使用的内核:
[root@zixiao-linux ~]#  uname -r
2.自动获取当前系统中的无用内核(未使用的)并进入卸载
[root@zixiao-linux ~]#  yum remove $(rpm -qa | grep kernel | grep -v $(uname -r))
ps:获取当前系统的全部内核列表
[root@zixiao-linux ~]# rpm -qa | grep kernel

修改系统语言

1.修改系统语言为为中文语言与编码
[root@zixiao-linux ~]# LANG="zh_CN.UTF-8" SYSFONT="latarcyrheb-sun16" SUPPORTED="zh_CN.UTF-8:zh_CN:zh"
2.修改系统语言为为英文语言与编码
[root@zixiao-linux ~]# LANG="en_US.UTF-8"
  • 工具安装类

修改yum源

cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.backup
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
mv CentOS6-Base-163.repo CentOS-Base.repo
yum clean all

安装lrzsz(linux系统里的一款上传和下载的工具)

解决Linux -bash: rz/sz: command not found
[root@zixiao-linux ~]# yum -y install lrzsz

安装压缩软件

解决Linux -bash: unzip: command not found
[root@zixiao-linux ~]# yum -y install unzip zip

安装openjdk

[root@zixiao-linux ~]# yum search java|grep jdk
[root@zixiao-linux ~]# yum install -y java-1.8.0-openjdk
ps:Linux安装JDK完整步骤:https://www.cnblogs.com/dingchuang666/p/14451479.html
  • 软件相关类

nacos单机启动命令

[root@zixiao-linux ~]# sh startup.sh -m standalone

gitlab操作命令

启动gitlab服务
[root@zixiao-linux ~]# sudo gitlab-ctl start
gitlab服务停止
[root@zixiao-linux ~]# sudo gitlab-ctl stop
重启gitlab服务
[root@zixiao-linux ~]# sudo gitlab-ctl restart
  • 其它

解决图形界面卡死

[root@zixiao-linux ~]# killall -9 gnome-shell

设置linux笔记本不关机,Linux-关闭笔记本盖不休眠

编辑下列文件:/etc/systemd/logind.conf
#HandlePowerKey按下电源键后的行为,默认power off
#HandleSleepKey 按下挂起键后的行为,默认suspend
#HandleHibernateKey按下休眠键后的行为,默认hibernate
#HandleLidSwitch合上笔记本盖后的行为,默认suspend(改为lock;即合盖不休眠)在原文件中,还要去掉前面的#
[root@zixiao-linux ~]# systemctl restart systemd-logind 就会生效.

关闭无线网卡的 电源管理 [wlp3s0是网卡名]

[root@zixiao-linux ~]# sudo iwconfig wlp3s0 power off
1、*.tar 用 tar –xvf  解压  
2、*. gz  用 gzip -d或者gunzip  解压  
3、*.tar. gz 和*.tgz 用 tar –xzf  解压  
4、*.bz2 用 bzip2 -d或者用bunzip2  解压  
5、*.tar.bz2用tar –xjf  解压  
6、*.Z 用 uncompress  解压  
7、*.tar.Z 用tar –xZf  解压  
8、*.rar 用 unrar e 解压  
9、*.zip 用 unzip  解压
rpm -e 需要卸载的安装包
--force 强制操作 如强制安装删除等;
--requires 显示该包的依赖关系;
--nodeps 忽略依赖关系并继续操作;
[root@zixiao-linux ~]# rpm -i example.rpm 安装 example.rpm 包;
[root@zixiao-linux ~]# rpm -iv example.rpm 安装 example.rpm 包并在安装过程中显示正在安装的文件信息;
[root@zixiao-linux ~]# rpm -ivh example.rpm 安装 example.rpm 包并在安装过程中显示正在安装的文件信息及安装进度;
[root@zixiao-linux ~]# rpm -qa | grep tomcat4
[root@zixiao-linux ~]# source /etc/profile
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

itzixiao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值