美文网首页
Linux 零散内容

Linux 零散内容

作者: 歌哥居士 | 来源:发表于2019-03-27 07:12 被阅读0次

yum源改为阿里云镜像

1、打开centos的yum文件夹
输入命令cd /etc/yum.repos.d/

2、用wget下载repo文件
输入命令wget http://mirrors.aliyun.com/repo/Centos-7.repo
如果wget命令不生效,说明还没有安装wget工具,输入yum -y install wget 回车进行安装。
当前目录是/etc/yum.repos.d/,刚刚下载的Centos-7.repo也在这个目录上

3、备份系统原来的repo文件
mv CentOs-Base.repo CentOs-Base.repo.bak
即是重命名 CentOs-Base.repo -> CentOs-Base.repo.bak

4、替换系统原理的repo文件
mv Centos-7.repo CentOs-Base.repo
即是重命名 Centos-7.repo -> CentOs-Base.repo

5、执行yum源更新命令
yum clean all
yum makecache
yum update
依次执行上述三条命令即配置完毕。

CentOS7 防火墙

CentOS7防火墙默认使用的是firewall,与之前的版本使用iptables不一样。

关闭防火墙
$ systemctl stop firewalld.service
关闭开机启动
$ systemctl disable firewalld.service
查看默认防火墙状态
$ firewall-cmd --state
安装iptables防火墙
$ yum install iptables-services
设置iptables防火墙开机启动
$ systemctl enable iptables

CentOS6 防火墙

关闭防火墙
$ service iptables stop
查询防火墙状态
$ service iptables status
检查启动是否开启防火墙
$ chkconfig iptables --list
关闭开机开启防火墙
$ chkconfig iptables off

将80转发到8081上

$ sudo systemctl stop firewalld.service
$ sudo systemctl disable firewalld.service
$ sudo yum install iptables-services
$ sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8081
$ sudo service iptables save
$ sudo systemctl restart iptables.service
$ sudo systemctl enable iptables.service
查看修改的结果
$ sudo vim /etc/sysconfig/iptables

 Generated by iptables-save v1.4.21 on Sat Feb 16 12:53:01 2019
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [3:3156]
:POSTROUTING ACCEPT [3:3156]
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8081
COMMIT
# Completed on Sat Feb 16 12:53:01 2019

终端快捷键

ctrl+r 搜索历史命令
ctrl+l 清屏
ctrl+a 移动到命令行首
ctrl+e 移动到命令行尾
ctrl+u 光标位置删除到行首
ctrl+z 命令放到后台

创建新用户

创建新用户

# adduser baozi
# passwd baozi
更改用户 baozi 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
(不用管密码提示无效、过于简单之类)

授权:给新用户添加sudo xxx的权限

# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz
# ls -al /etc | grep sudoers
-r--r-----   1 root root     4328 10月 30 22:38 sudoers
drwxr-x---.  2 root root     4096 10月 31 08:36 sudoers.d
# chmod -v u+w /etc/sudoers
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)
# vim /etc/sudoers
  ## Allow root to run any commands anywhere
  root    ALL=(ALL)       ALL
  baozi   ALL=(ALL)       ALL  #这是新增的
# chmod -v u-w /etc/sudoers
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)

相关文章

网友评论

      本文标题:Linux 零散内容

      本文链接:https://www.haomeiwen.com/subject/vhnxvqtx.html