Linux 常用命令

防火墙相关

查看防火墙:

chkconfig iptables --list          # centos 6
firewall-cmd --state			   # centos 7

永久关闭防火墙:

chkconfig iptables off			# centos 6

# centos 7
systemctl stop firewalld.service  	    	# 停止防火墙
systemctl disable firewalld.service 		# 禁止开机启动

CentOS 6/7 关闭防火墙

Debain 系列默认没有开启和安装防火墙




SSH 免密:

SSH 免密登录
在 .ssh 目录下输入如下命令然后回车四次

ssh-keygen -t rsa

使用

ssh-copy-id  hostName   

把生成的公钥复制到需要免密登录的服务器上
配置了免密的服务器注意要把公钥复制给自己一份, 免密登录自己.




主机名

修改主机名:

vim /etc/sysconfig/network 				CentOS/RedHat

vim /etc/hostname       	Ubantu/Debain
Hosts 文件

修改 host 映射

vim /etc/hosts



远程拷贝

远程拷贝:

scp  localDir/localFile root@hostName:/remoteDir/remoteFile



时间相关:
date        查看当前系统时间

date -s 2009-05-07      修改日期,将日期设定成2009年5月7日

date -s 20:18:00        修改时间,将时间设定成下午8点18分0秒

clock -w                同步BIOS时钟,强制把系统时间写入CMOS



查看并卸载自带JDK

针对 CentOS 和 红帽发行版本:

rpm -qa | grep java
yum -y remove  JDKVersion

针对 Ubuntu 和 Debain 发行版本:

sudo apt-get remove openjdk*



查看系统版本
lsb_release -a 

即可列出所有版本信息:




安装 SSH 服务

Debain9, 其他Linux 类似
安装:

apt install openssh-server openssh-client

启动:

/etc/init.d/ssh start

添加开机启动:

update-rc.d ssh enable

修改 /etc/ssh/sshd_config 配置允许 root 登录, 添加

PermitRootLogin yes

修改完 /etc/ssh/sshd_config 后需要重启 ssh 服务:

service sshd restart



SELinux 相关:

查看状态:

sestatus

关闭 SELinux:

vim /etc/selinux/config

将其设置为 disabled




系统升级:

CentOS , RedHat 系列:

sudo yum clean all

sudo yum update

Ubuntu, Debian 系列:





安装 htop:

CentOS ,RedHat:

先安装依赖
yum -y install epel-release

再安装 htop
yum -y install htop

详情


Ubuntu, Debian:

暂无尝试, 鄙人用的 Debian 自带 htop

详情




安装 iftop 网络监控

CentOS, RedHat

yum install epel-release 

yum install iftop

详情

Ubuntu, Debian:

apt install iftop



更换 yum 源

Centos , RHEL

先备份:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

后更换:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

最后生成缓存使其生效:

yum makecache

详情


Ubuntu, Debian

暂无尝试

树莓派 Debian 10:
详情




nohup 后台运行
nohup command > outPut.log 2>&1 &

后台运行, 并把日志重定向到 outPut.log, 其中 2>&1 的含义为把标准错误输出也定向到标准输出, 最后一个 & 标识后台运行.

详情




查看 mysql 状态:

如果添加了 mysqld 的服务的话,

service mysqld status

查看 mysqld 服务的开机启动情况:

chkconfig --list

关闭 mysqld 开机启动:

chkconfig --level 345 mysqld off 



时间同步

同步某一个时间服务器

service ntpd status

ntpd cn.ntp.org.cn  		 #	cn.ntp.org.cn 是一个时间服务器

其他详情

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值