ReZero's Utopia.

Linux fun tool

Word count: 1.9kReading time: 9 min
2018/02/20 Share

FTP service setup

  1. Setup vsftpd sudo apt-get install vsftpd -y

  2. Start vsftpd

    • check whether the port 21 is working sudo netstat -nltp | grep 21
    • if the above not start, you can do it manually sudo systemctl start vsftpd.service
  3. Config the User directory

    • make a directory sudo mkdir /home/uftp
    • make a welcome file sudo touch /home/uftp/welcome.txt
    • config user and create passwd
    • sudo useradd -d /home/uftp -s /bin/bash uftp
    • sudo passwd uftp
    • remove the file to avoid login failed. sudo rm /etc/pam.d/vsftpd
  4. Do some limitation

    • make the user only access the ftp instead of login the server sudo usermod -s /sbin/nologin uftp

    • config again sudo chmod a+w /etc/vsftpd.conf

      # 限制用户对主目录以外目录访问
      chroot_local_user=YES
      
      # 指定一个 userlist 存放允许访问 ftp 的用户列表
      userlist_deny=NO
      userlist_enable=YES
      
      # 记录允许访问 ftp 用户列表
      userlist_file=/etc/vsftpd.user_list
      
      # 不配置可能导致莫名的530问题
      seccomp_sandbox=NO
      
      # 允许文件上传
      write_enable=YES
      
      # 使用utf8编码
      utf8_filesystem=YES
*   create the access file for user list `sudo touch /etc/vsftpd.user_list` `sudo chmod a+w /etc/vsftpd.user_list` modify the user_list as followed: `uftp`
*   config the access authority
    *   the main dir only read `sudo chmod a-w /home/uftp`
    *   the pulic dir can be read and wrote `sudo mkdir /home/uftp/public && sudo chmod 777 -R /home/uftp/public`
*   restart the service `sudo systemctl restart vsftpd.service`
  1. Prepare the domain and just make the analyze ip then everything will be ok.

Arch enable bbr

Requests: kernel 4.9+


What: https://github.com/google/bbr One Command: sudo modprobe tcp_bbr Turn on:

# echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
# echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
# sysctl -p
# sysctl net.ipv4.tcp_available_congestion_control
# sysctl net.ipv4.tcp_congestion_control

Enable It:

# echo "net.core.default_qdisc=fq" >> /etc/sysctl.d/tcp-bbr.conf
# echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.d/tcp-bbr.conf

Check:

lsmod | grep bbr

arch gdm background

Link https://superuser.com/a/1292700/695553

#!/bin/bash

if [ -z "$1" ]; then
  echo "Usage: ./chgdm-bg <path/to/picture.png> [y/n]"
  exit 1
fi

echo MAKE SURE YOUR PICTURE IS THE SAME RESOLUTION AS YOUR SCREEN.
echo If you dont you will likely regret it.
sleep 3

if [ ! -f $1 ]; then
  echo Error: could not find file $1
  exit 1
fi

PIC=$1
WORKDIR=${HOME}/chgdm-bg-tmp
DATE=$(date +"%Y-%m-%d_%T")

if [ ! -d $WORKDIR ]; then
  mkdir -p $WORKDIR/theme
fi

cd "${WORKDIR}/theme"
mkdir -p backups

IFS='/' read -r -a array <<< "$PIC"
cp $PIC .
PIC=${array[-1]}
chmod 777 $PIC

SHARE=/usr/share/gnome-shell/
GRESOURCE=gnome-shell-theme.gresource
CSS=gnome-shell.css
XMLRES=gnome-shell-theme.gresource.xml

if [ -f ${SHARE}${GRESOURCE} ]; then
  echo Backing up ${SHARE}${GRESOURCE}...
  cp ${SHARE}${GRESOURCE} "backups/${GRESOURCE}.bak.${DATE}"
  cp ${SHARE}${GRESOURCE} $GRESOURCE
  printf "Unpacking binary resource..."
  for r in `gresource list $GRESOURCE`; do
    printf "."
    gresource extract $GRESOURCE $r >$WORKDIR/${r#\/org\/gnome\/shell/}
  done
  echo
  WORKDIR="${WORKDIR}/theme/"


  if [ -f ${XMLRES} ]; then
    echo Backing up ${XMLRES}...
    cp "${XMLRES}" "backups/${XMLRES}.bak.${DATE}"
    if [ -f "tmp" ]; then
      rm -f tmp
    fi
    touch tmp
    awk -v var="$PIC" '/gresource prefix="\/org\/gnome\/shell\/theme">/ { print; printf "    <file>"; printf var; print "<\/file>"; next }1' $XMLRES > tmp && mv tmp $XMLRES
    #sed -n -i "/\ \ \ \ <file>$PIC<\/file>/d" $XMLRES
    #sed -n -i "/gresource prefix=\"\/org\/gnome\/shell\/theme\">/a \ \ \ \ <file>$PIC<\/file>" $XMLRES
  else
    echo Error: could not find file ${XMLRES}
    exit 1
  fi

  if [ -f $CSS ]; then
    echo Backing up $CSS...
    cp $CSS "backups/${CSS}.bak.${DATE}"
    sed -i 's/#lockDialogGroup/#lockDialogGroup-old/' $CSS
    printf "#lockDialogGroup {\n    background: #2e3436 url(${PIC});\n    background-repeat: no-repeat;\n    background-size: cover; }\n" >> $CSS
  else
    echo Error: could not find file $CSS
    exit 1
  fi

  echo Compiling binary resources...
  glib-compile-resources $XMLRES
  echo Copying binary resources over to ${SHARE}...
  sudo cp $GRESOURCE "${SHARE}${GRESOURCE}"
  sudo cp $CSS "${SHARE}${CSS}"

  if [ -z $2 ]; then
    echo "Restart now? (y/n)"
    read ans
  fi

  if [ "$2" = "y" ] || [ "$ans" = "y" ]; then
    echo Restarting...
    for i in {1..5}; do
      echo $((6-i))
      sleep 1
    done
    #/usr/bin/gnome-session-quit --no-prompt
    #sudo pkill -u $USER
    sudo shutdown -r now
  else
    echo Restart to load your changes.
  fi
else
  echo Error: could not find file ${SHARE}${GRESOURCE}
  exit 1
fi

Save as cb.sh, and execute sudo chmod +x cb.sh & ./cb.sh backgoundFilePath command.

IpTables & Firewalld

iptables

PreRouting, Input, Output, Forward, PostRouting

参数

作用

-P

设置默认策略

-F

清空规则链

-L

查看规则链

-A

在规则链的末尾加入新规则

-I num

在规则链的头部加入新规则

-D num

删除某一条规则

-s

匹配来源地址IP/MASK,加叹号“!”表示除这个IP外

-d

匹配目标地址

-i

网卡名称 匹配从这块网卡流入的数据

-o

网卡名称 匹配从这块网卡流出的数据

-p

匹配协议,如TCP、UDP、ICMP

–dport num

匹配目标端口号

–sport num

匹配来源端口号

  1. iptables -L View existing iptables rule

  2. iptables -F Empty the rules

  3. iptables -P INPUT DROP Default set DROP

  4. iptables -I INPUT -p icmp -j ACCEPT allow ping(icmp)

  5. iptables -I INPUT -s 192.168.10.0/24 -p tcp --dport 22 -j ACCEPT Only allow appoint network segment access 22.

  6. iptables -A INPUT -p tcp --dport 22 -j REJECT Forbidden others host flow

  7. service iptables save Make it effect permanently

FireWalld

区域

默认规则策略

trusted

允许所有的数据包

home

拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh、mdns、ipp-client、| amba|-client与dhcpv6-client服务相关,则允许流量

internal

等同于home区域

work

拒绝流入的流量,除非与流出的流量数相关;而如果流量与ssh、ipp-client与dhcpv6-client| 服务相关,则允许流量

public

拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh、dhcpv6-client服务相关,则允许| 流量

external

拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh服务相关,则允许流量

dmz

拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh服务相关,则允许流量

block

拒绝流入的流量,除非与流出的流量相关

drop

拒绝流入的流量,除非与流出的流量相关

  1. firewall-cmd --get-default-zone View current using area

  2. firewall-cmd --get-zone-of-interface=eno16728 View eno netCard wroking area

  3. firewall-cmd --permanent --zone=external --change-interface=eno16278 Set area as external and take effect after restarting system.

  4. firewall-cmd --panic-on Meet an emergency, stop all connections.

  5. firewall-cmd --znoe=public --query-service=https View whether could pass https flow, u can also use –add-service=https(protocol name) to add pass power and –remove-service=https(protocol name) to reject it.

  6. firewall-cmd --reload Take permanent effect immediately.

  7. firewall-cmd --zone-=public --add-forward-port=port=888:proto=tcp:toport=22:toaddr=192.168.10.10 Forward access 888 port flow to 22 port.

Service access control list

# Rules
Match /etc/hosts.allow?pass
    :Match /etc/hosts.deny?forbidden
        :pass
  1. Two Principles
  • Reject strategy: service name instead protocol

  • Reject strategy editting should be first.

  1. hosts.deny sshd:*

  2. hosts.allow sshd:192.168.10.

参数

作用

–get-default-zone

查询默认的区域名称

–set-default-zone=<区域名称>

设置默认的区域,使其永久生效

–get-zones

显示可用的区域

–get-services

显示预先定义的服务

–get-active-zones

显示当前正在使用的区域与网卡名称

–remove-source=

将源自此IP或子网的流量导向指定的区域

–remove-source=

不再将源自此IP或子网的流量导向某个指定区域

–add-interface=<网卡名称>

将源自该网卡的所有流量都导向某个指定区域

–change-interface=<网卡名称>

将某个网卡与区域进行关联

–list-all

显示当前区域的网卡配置参数、资源、端口以及服务等信息

–list-all-zones

显示所有区域的网卡配置参数、资源、端口以及服务等信息

–add-service=<服务名>

设置默认区域允许该服务的流量

–add-port=<端口号/协议>

设置默认区域允许该端口的流量

–remove-service=<服务名>

设置默认区域不再允许该服务的流量

–remove-port=<端口号/协议>

设置默认区域不再允许该端口的流量

–reload

让“永久生效”的配置规则立即生效,并覆盖当前的配置规则

–panic-on

开启应急状况模式

–panic-off

关闭应急状况模式

CATALOG
  1. 1. FTP service setup
  • Arch enable bbr
  • arch gdm background
  • IpTables & Firewalld
    1. 1. iptables
    2. 2. FireWalld
    3. 3. Service access control list