Jade Dungeon

系统安装备忘

手动安装

备份

备份没有在github上存着的东西: offlineimap、msmtprc、pidgin聊天记录、firefox 收藏夹 等等……继续补充……

安装

好像一时还想不到什么话说……

debian 7

deb http://mirrors.sohu.com/debian/ wheezy main non-free contrib
# deb http://mirrors.sohu.com/debian/ wheezy-proposed-updates main non-free contrib
deb-src http://mirrors.sohu.com/debian/ wheezy main non-free contrib
# deb-src http://mirrors.sohu.com/debian/ wheezy-proposed-updates main non-free contrib

deb http://ftp.cn.debian.org/debian/ wheezy main contrib non-free
deb http://ftp.cn.debian.org/debian-security/ wheezy/updates main contrib non-free
# deb http://ftp.cn.debian.org/debian-multimedia/ wheezy main contrib non-free
deb-src http://ftp.cn.debian.org/debian/ wheezy main contrib non-free

# deb http://mirrors.163.com/debian/ wheezy main contrib non-free
# deb http://mirrors.163.com/debian-security/ wheezy/updates main contrib non-free
# deb-src http://mirrors.163.com/debian/ wheezy main contrib non-free

deb http://ftp2.jp.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp2.jp.debian.org/debian/ wheezy main contrib non-free

deb http://ftp.jp.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp.jp.debian.org/debian/ wheezy main contrib non-free

deb http://ftp.tw.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp.tw.debian.org/debian/ wheezy main contrib non-free

deb http://security.debian.org/ wheezy/updates main contrib non-free
deb-src http://security.debian.org/ wheezy/updates main contrib non-free

deb http://downloads.sourceforge.net/project/ubuntuzilla/mozilla/apt all main

debian 8

deb http://mirrors.sohu.com/debian/ jessie main non-free contrib
# deb http://mirrors.sohu.com/debian/ jessie-proposed-updates main non-free contrib
deb-src http://mirrors.sohu.com/debian/ jessie main non-free contrib
# deb-src http://mirrors.sohu.com/debian/ jessie-proposed-updates main non-free contrib

deb http://mirrors.163.com/debian/ jessie main non-free contrib
deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib
deb http://mirrors.163.com/debian/ jessie-backports main non-free contrib
# deb-src http://mirrors.163.com/debian/ jessie main non-free contrib
# deb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib
# deb-src http://mirrors.163.com/debian/ jessie-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib
# deb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib

deb http://mirrors.ustc.edu.cn/debian jessie main contrib non-free
deb http://mirrors.ustc.edu.cn/debian jessie-proposed-updates main contrib non-free
deb http://mirrors.ustc.edu.cn/debian jessie-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian jessie-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian jessie main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian jessie-proposed-updates main contrib non-free

deb http://ftp.cn.debian.org/debian/ jessie main contrib non-free
deb http://ftp.cn.debian.org/debian-security/ jessie/updates main contrib non-free
# deb http://ftp.cn.debian.org/debian-multimedia/ jessie main contrib non-free
deb-src http://ftp.cn.debian.org/debian/ jessie main contrib non-free

# deb http://mirrors.163.com/debian/ jessie main contrib non-free
# deb http://mirrors.163.com/debian-security/ jessie/updates main contrib non-free
# deb-src http://mirrors.163.com/debian/ jessie main contrib non-free

deb http://ftp2.jp.debian.org/debian/ jessie main contrib non-free
deb-src http://ftp2.jp.debian.org/debian/ jessie main contrib non-free

deb http://ftp.jp.debian.org/debian/ jessie main contrib non-free
deb-src http://ftp.jp.debian.org/debian/ jessie main contrib non-free

deb http://ftp.tw.debian.org/debian/ jessie main contrib non-free
deb-src http://ftp.tw.debian.org/debian/ jessie main contrib non-free

deb http://security.debian.org/ jessie/updates main contrib non-free
deb-src http://security.debian.org/ jessie/updates main contrib non-free

deb http://downloads.sourceforge.net/project/ubuntuzilla/mozilla/apt all main

debian 10

deb http://mirrors.cloud.aliyuncs.com/debian/ buster main non-free contrib
deb-src http://mirrors.cloud.aliyuncs.com/debian/ buster main non-free contrib
deb http://mirrors.cloud.aliyuncs.com/debian-security buster/updates main
deb-src http://mirrors.cloud.aliyuncs.com/debian-security buster/updates main
deb http://mirrors.cloud.aliyuncs.com/debian/ buster-updates main non-free contrib
deb-src http://mirrors.cloud.aliyuncs.com/debian/ buster-updates main non-free contrib
deb http://mirrors.cloud.aliyuncs.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.cloud.aliyuncs.com/debian/ buster-backports main non-free contrib

禁用snap

已经确认 snapd 是无法禁用的,只能强制删除。以下操作无需停止 snapd 服务。

snap list 用于查看已经安装的 Snap 软件,通过脚本全部删除:

for p in $(snap list | awk '{print $1}'); do
  sudo snap remove $p
done

一般需要执行两次(桌面版三次),提示如下则正确执行:

snap "Name" is not installed
core20 removed
snapd removed

再次执行,提示如下,表明已经删除干净:

No snaps are installed yet. Try 'snap install hello-world'.

删除 Snap 的 Core 文件。

sudo systemctl stop snapd
sudo systemctl disable --now snapd.socket

for m in /snap/core/*; do
   sudo umount $m
done

删除 Snap 的管理工具。

sudo apt autoremove --purge snapd

删除 Snap 的目录。

rm -rf ~/snap
sudo rm -rf /snap
sudo rm -rf /var/snap
sudo rm -rf /var/lib/snapd
sudo rm -rf /var/cache/snapd

配置 APT 参数:禁止 apt 安装 snapd。

sudo sh -c "cat > /etc/apt/preferences.d/no-snapd.pref" << EOL
Package: snapd
Pin: release a=*
Pin-Priority: -10
EOL
a -> Archive
c -> Component
o -> Origin
l -> Label
n -> Architecture

验证效果:可以查询到该包,但是无法安装。

# sysin @ u22 in ~ [13:59:22]
$ apt list snapd
Listing... Done
snapd/jammy-updates 2.56.2+22.04ubuntu1 amd64
N: There is 1 additional version. Please use the '-a' switch to see it

# sysin @ u22 in ~ [13:59:37]
$ sudo apt install snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package snapd is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'snapd' has no installation candidate

同时禁用 snap Firefox 的更新(Server 版也可以配置):

sudo sh -c "cat > /etc/apt/preferences.d/no-firefox.pref" << EOL
Package: firefox
Pin: release a=*
Pin-Priority: -10
EOL

现在服务器版安装桌面环境也没有 Snap!

sudo apt update
#sudo apt install ubuntu-desktop  #完整 GNOME 桌面环境包括 LibreOffice、视频播放器、游戏等等
sudo apt install ubuntu-desktop-minimal  #仅浏览器和基本工具
sudo reboot

系统安装

neofetch是用来查看系统信息的不错软件

$ sudo apt-get install neofetch

$ neofetch
            .-/+oossssoo+/-.               jade@DST011350
        `:+ssssssssssssssssss+:`           --------------
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 22.04.3 LTS on Windows 10 x86_64
    .ossssssssssssssssssdMMMNysssso.       Kernel: 4.4.0-19041-Microsoft
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Uptime: 3 days, 3 hours, 58 mins
  +ssssssssshmydMMMMMMMNddddyssssssss+     Packages: 1287 (dpkg)
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Shell: zsh 5.8.1
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Theme: Adwaita [GTK3]
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Icons: Adwaita [GTK3]
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   Terminal: tmux
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   CPU: AMD Ryzen 5 3600 (12) @ 3.600GHz
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Memory: 13605MiB / 32702MiB
.ssssssssdMMMNhsssssssssshNMMMdssssssss.
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/
  +sssssssssdmydMMMMMMMMddddyssssssss+
   /ssssssssssshdmNNNNmyNMMMMhssssss/
    .ossssssssssssssssssdMMMNysssso.
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`
            .-/+oossssoo+/-.


配置

主机名

改了/etc/hostname以后,别忘记了还有/etc/hosts

locale

安装locales程序:

apt-get install locales

sudo locale-gen

如果是WSL1环境下,GZIP会禁用,导致报错character map file UTF-8 not found: No such file or directory

I ran into this same symptom (locale-gen can't find charmap files) after upgrading from Ubuntu 20.04 to 22.04 in WSL 1. The problem is that there is a bug in WSL 1 that prevents gunzip from running. This is a problem for locale-gen because, at least in Ubuntu 22.04, the charmap files in /usr/share/i18n/charmaps are stored in GZip *.gz format. Apparently, locale-gen depends on gunzip to unzip the charmap files, and when it can't run it, it is stuck.

The solution was

  • copy UTF-8.gz to the Windows filesystem
  • unzip it to UTF-8 with a Windows tool (such as 7-zip)
  • copy UTF-8 back to /usr/share/i18n/charmaps

Then locale-gen worked correctly.

然后配置所用的语系:

dpkg-reconfigure locales

中文常用的的locale:

  • en_US.ISO-8859-1
  • en_US.UTF-8
  • zh_CN.GB2312
  • zh_CN.GB18030
  • zh_CN.UTF-8
  • zh_CN.GBK
  • zh_TW.BIG5
  • zh_TW.UTF-8

缺省locale为en_US.utf8,

这样就完成了,可以查看一下中的语系:

locale -a

修改系统的语言设置/etc/default/locale

LANG="en_US.UTF-8"
LANGUAGE="en_US:en"

时间

方法一:

sudo apt-get install ntp
sudo ntpdate ntp.ntsc.ac.cn
# sudo ntpdate ntp1.aliyun.com
# sudo ntpdate cn.pool.ntp.org

方法二:

时钟是否与互联网同步:

$ timedatectl
                      Local time: Thu 2020-10-08 23:10:17 CST  # 本地时间
                  Universal time: Thu 2020-10-08 15:10:17 UTC  # 世界时
                        RTC time: Thu 2020-10-08 15:10:17      
                       Time zone: Asia/Shanghai (CST, +0800)   # 时区
       System clock synchronized: yes                          # 是否与互联网同步
systemd-timesyncd.service active: yes                          # 时间服务器是否有效
                 RTC in local TZ: no

如果System clock synchronized没有开启,尝试重启:

sudo systemctl restart systemd-timesyncd.service

再次查看状态:

$ sudo systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-07-30 10:50:18 UTC; 1h 11min ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 498 (systemd-timesyn)
Status: "Synchronized to time server [2001:67c:1560:8003::c7]:123 (ntp.ubuntu.com)."
Tasks: 2 (limit: 2319)
CGroup: /system.slice/systemd-timesyncd.service
└─498 /lib/systemd/systemd-timesyncd

Jul 30 10:50:30 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estab
Jul 30 10:50:31 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estab
Jul 30 10:50:31 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estab
Jul 30 10:50:32 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estab
Jul 30 10:50:32 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estab
Jul 30 10:50:35 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estab
Jul 30 10:50:35 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estab
Jul 30 10:50:35 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estab
Jul 30 10:50:35 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estab
Jul 30 10:51:06 ubuntuserver systemd-timesyncd[498]: Synchronized to time server [2001:67c:1560:800

令验证是否启用了时间同步:

$ timedatectl

如果仍然不起作用,请运行以下命令以启用时间同步:

$ sudo timedatectl set-ntp true

用户

添加常用账号,默认会建立同名组:

groupadd user001
useradd user001 -g user001 -d /home/user001 -s /usr/bin/zsh

修改密码:

passwd user001

建立用户目录,别忘记修改权限,不然什么东西都被人家看到……(羞):

mkdir /home/user001
chgrp user001 /home/user001
chown user001 /home/user001
chmod 700 /home/user001

同步用户和组(不过不是直接修改配置文件的话应该用不着):

grpconv

再提醒一下自己以后删除用户的时候不要-r参数忘记删除home目录和mail。 还有 userdel会把用户的组也一块删除掉,当心当心:

userdel -r user001

用于天朝特色用途的账号,没有登录的必要。不给shell:

useradd user001 -g user001 -s /bin/false

sudo

「To err is human, but to really foul up everything, you need root password.」

「人非圣贤孰能无过,但是拥有root密码就真的万劫不复了。」

安装sudo

apt-get install sudo

编辑/etc/sudoers增加sudo权限:

user001 ALL=(ALL) ALL

更详细的配置介绍:

别名设置

别名主要分成4种,分别是:

1)Host_Alias主机别名,就是主机的列表。如:

Host_Alias HOST_FLAG = hostname1, hostname2, hostname3

2)Cmnd_Alias命令别名,就是允许执行的命令的列表。如:

Cmnd_Alias COMMAND_FLAG = command1, command2, command3

3)User_Alias用户别名,就是具有sudo权限的用户的列表。如:

User_Alias USER_FLAG = user1, user2, user3

4)Runas_Alias Runas别名,就是用户以什么身份执行(例如root,或者oracle)的列表 。如:

Runas_Alias RUNAS_FLAG = operator1, operator2, operator3

别名格式是:

Alias_Type NAME = item1, item2, ……

权限设置

首先看看授权规则。格式:

授权用户 主机 = [(目的用户)] [NOPASSWD:] 命令列表

如:

tony ALL=(ALL) NOPASSWD:ALL

其中NOPASSWD是指不需要密码验证

配置文件完整的例子:

# groups
User_Alias  ROOT = user1, user2, user3
User_Alias  WEBMASTERS = user4, user5, user6
  
# commands
Cmnd_Alias  APACHE = /usr/local/sbin/kickapache
Cmnd_Alias  TAIL = /usr/bin/tail
Cmnd_Alias      SHUTDOWN = /sbin/shutdown
Cmnd_Alias      APT = /usr/bin/apt-get, /usr/bin/dpkg
  
# privileges
ROOT        ALL = (ALL) ALL
WEBMASTERS  ALL = PASSWD : APACHE, TAIL
admin       ALL = NOPASSWD : /etc/init.d/apache

参数:

  • -l 显示出自己(执行 sudo 的使用者)的权限
  • -v 因为 sudo 在第一次执行时或是在 N 分钟内没有执行(N 预设为五)会问密码,这个参数是重新做一次确认,假如超过 N 分钟,也会问密码
  • -k 将会强迫使用者在下一次执行 sudo 时问密码(不论有没有超过 N 分钟)
  • -b 将要执行的指令放在后台执行
  • -p prompt 能够更改问密码的提示语,其中 %u 会代换为使用者的帐号名称, %h 会显示主机名称
  • -u username/#uid 不加此参数,代表要以 root 的身份执行指令,而加了此参数,能够以 username 的身份执行指令(#uid 为该 username 的使用者号码)
  • -s 执行环境变量中的 SHELL 所指定的 shell ,或是 /etc/passwd 里所指定的 shell
  • -H 将环境变数中的 HOME (家目录)指定为要变更身份的使用者家目录(如不加 -u 参数就是系统管理者 root )

安全设置

SSH

修改SSH端口,禁止root远程登录,/etc/ssh/sshd_config

Port 1234
PermitRootLogin no
AllowUsers user01

重启服务:

service sshd restart

或是:

sudo /etc/init.d/ssh restart

生成登录用的密钥

ssh-keygen -t rsa

把公钥上传到服务器:

cat  ~/.ssh/id_rsa.pub | ssh user001@192.168.1.1 "cat - >> ~/.ssh/authorized_keys"

如果密钥中设置了passphrase,则需要输passphrase登录服务器。为了更方便可以 通过ssh-agent来帮助修改~/.ssh/id_rsa文件。看起来像是自动输入passphrase(只是 像而已):

ssh-add

备注:对于SSH2兼容格式的公钥,可以转换成为Openssh兼容格式

ssh-keygen -i -f Identity.pub >> /root/.ssh/authorized_keys2

禁止密码登录,只允许key登录:还不知道怎么搞~OTZ

删除已经有的公钥,比如pi.home-cluster这台机器重装系统或是公钥变了,可以:

ssh-keygen -f "/home/jade/.ssh/known_hosts" -R pi.home-cluster

iptables

清除已有的规则:

iptables -F
iptables -X
iptables -Z

开放常用的端口:

# 允许本地回环接口
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
# 放行已经连接的相关连接
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# 不限制外出
iptables -A OUTPUT -j ACCEPT
# 放行常用入口请求 ssh http ftp
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
# 同样格式的其他入口
# 禁止其他访问入口,注意别把ssh的22端口给禁了
iptables -A INPUT -j REJECT
iptables -A FORWARD -j REJECT
 
# 封一个IP
iptables -I INPUT -s 123.45.6.7 -j DROP
# 封123.0.0.1~123.255.255.254整个段
iptables -I INPUT -s 123.0.0.0/8 -j DROP
# 封123.45.0.1到123.45.255.254
iptables -I INPUT -s 124.45.0.0/16 -j DROP
# 封123.45.6.1到123.45.6.254
iptables -I INPUT -s 123.45.6.0/24 -j DROP

检查已经添加的规则:

iptables -L -n --line-numbers

可以按显示的chain类与行号删除一条规则,如INPUT中的第3条:

iptables -D INPUT 3

网卡启动时加载规则/etc/network/if-pre-up.d/iptables

#!/bin/bash
iptables-restore < /etc/iptables.rules

权限:

chmod +x /etc/network/if-pre-up.d/iptables

网卡关闭时保存规则/etc/network/if-post-down.d/iptables

#!/bin/bash
iptables-save > /etc/iptables.rules

权限:

chmod +x /etc/network/if-post-down.d/iptables

iptables-persistent

这是debian内用于iptables规则持久化的工具,你可以编辑/etc/iptables/rules.v4来 修改防火墙规则。一般来说,至少要包含以下内容:

-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i tun+ -j ACCEPT
-A INPUT -i ppp+ -j ACCEPT
-A INPUT -p tcp -m multiport –dport 22,xxx,xxx,xxx -j ACCEPT
-A INPUT -p udp -m multiport –dport xxx,xxx,xxx -j ACCEPT

强烈建议先保存一个没问题的iptables,然后直接修改iptables,再保存。这样当改错了 导致无法管理的时候,只要重启就可以恢复vps工作。

denyhosts

python编写用来踢掉试图尝试ssh密码的ip。如果已经用了通过key的连接方式,你可以一次 就直接踢掉对方ip。

网络管理

ifstat

ifstat是用于网络流量管理的工具,可以告诉你网络目标的流量是多少。

dnsutils

dnsutils里面包含了不少用于管理dns的工具,包括我们常用的nslookup,还有相对少用的 dig。

mtr-tiny

mtr是一个traceroute工具,比后者好用很多。这个工具可以快速跟踪路由。

vnstat

vnstat是用于跟踪网卡流量的工具,尤其对于每个月都有限额的vps,这个工具更有意义。 注意安装完成后需要初始化每个网卡,然后重启服务,而不是马上能够工作。

网络服务

pptp

pptp是一个经典的vpn服务,直接安装pptpd就好。注意,部分手机不支持128bit的mppe, 关闭后可以连接。但是windows只支持128bit的mppe,关掉就无法连接。So,自己权衡。

openvpn

openpn是一个非常稳定而强大的vpn程序,他使用udp作为连接协议。其实openvpn有tcp协议 模式,但是速度比udp慢很多。openvpn的配置可以参考贝壳童鞋的文章(反正很本文很多 工具都是从他blog上学来的):

1.搭建家用的OpenVPN服务器:http://shell909090.com/blog/2009/09/%E6%90%AD%E5%BB%BA%E5%AE%B6%E7%94%A8%E7%9A%84openvpn%E6%9C%8D%E5%8A%A1%E5%99%A8/ 2.说说x509证书链:http://shell909090.com/blog/2011/04/%E8%AF%B4%E8%AF%B4x509%E8%AF%81%E4%B9%A6%E9%93%BE/ 3.再论openvpn的搭建:http://shell909090.com/blog/2011/05/%E5%86%8D%E8%AE%BAopenvpn%E7%9A%84%E6%90%AD%E5%BB%BA/

ssh

ssh用于翻墙常见两种模式,固定端口转发和动态端口转发。前者使用-R将远程的某个 端口映射到本地。通常而言,映射的都是squid或者polipo(推荐后者,内存消耗更小, 更好配置)。这样相当于在 本地可以访问远程的代理,从而达到翻墙的效果。命令:

ssh -L port:localhost:port …

而动态端口转发则是使用:

ssh -D port …

将本地的port端口变成一个支持socks5协议的代理服务器。相比而言,-D模式更加灵活, 提供了全协议的访问, 本地可以通过polipo转换为http代理。而-L模式则不能提供 socks5代理功能(除非远程的端口上是socks5代理服务,但是这样就回到了-D模式, 反而多开了一个服务)。但是有些时候(例如android的ssh翻墙软件)只支持后者的模式。

另外,不要用日常管理帐号翻墙。新开一个翻墙帐号,并且设定独立的key。然后禁用shell ,在ssh的时候,使用参数-CNq,这个参数可以不打开shell。如果网络不稳定,可以加上 -o ServerAliveInterval 30

stunnel

stunnel本身没有任何功效,他只是将你的普通连接转换为ssl连接而已。当这个程序搭配 其他程序,例如polipo,就可以实现一个ssl级别的代理。

httptunnel

这是一个服务软件,服务器端运行一个httptunnel,客户端运行一个。而后客户端就可以 获得一个到服务器端的tcp连接,不受限的。

polipo

polipo常见有两种模式,端口转发模式和ssl模式。两者都在前文有说。端口转发模式配合 ssh用,ssl模式配合stunnel用。以上的服务看似很多,实际上,在128M内存的实例上完全 可以运行其中大部分的服务。你可以在一台服务器上运行其中多个,以保证全天候的服务。

kickstart自动安装

安装kickstart:

sudo dpkg -i system-config-kickstart.deb 

以当前机器的配置生成安装模板

生成配置文件:

sudo system-config-kickstart --generate ks.cfg

生成的配置文件里好像没有分区信息。所以要手动加一下。查找 #partition clearing information。在clearpart --linux下增加分区:

part /boot --bytes-per-inode=4096 --fstype="ext3" --size=100
part swap --bytes-per-inode=4096 --fstype="swap" --size=512
part / --bytes-per-inode=4096 --fstype="ext3" --grow --size=1

把配置文件加入到安装镜像

编辑光盘中的isolinux目录下的test.cfg文件,找到第一个标签在append后加上 ks=cdrom:/install/ks.cfg

ks.cfg保存到IOS文件中的install目录中,把test.cfg覆盖以前的文件。

启动之后只需要直接回车安装就可以直接安装。

其他常用的kickstart配置内容

一个例子:


ubuntu配置安装包

安装uck来定制自己ubuntu系统的包。uck-gui启动,选择语言,在定制cd这一步时选择 yes。然后安装过程中选择启动命令行,安装或卸载自己需要的包。在弹出的命令行中:

先配置软件源:

# deb cdrom:[Ubuntu 14.04 LTS _Trusty Tahr_ - Release amd64 (20140417)]/ trusty main restricted

# deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
# deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
# deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
# deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
# deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse

deb http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse
# deb-src http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
# deb-src http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
# deb-src http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse
# deb-src http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
# deb-src http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ trusty universe
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
deb http://archive.canonical.com/ubuntu trusty partner
# deb-src http://archive.canonical.com/ubuntu trusty partner

## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu trusty main
# deb-src http://extras.ubuntu.com/ubuntu trusty main

安装自己要的包:

apt-get install abcde alex alsa-base alsa-firmware-loaders alsamixergui alsa-oss alsa-tools alsa-tools-gui alsa-utils alsoft-conf amule amule-common amule-utils autoconf automake autotools-dev awesome cheese cheese-common chm2pdf cifs-utils cl-asdf cli-common clisp cmake conky conky-std cpp cpp-4.8 dia dia-common dia-libs dkms easytag emacs24 emacs24-bin-common emacs24-common emacs24-common-non-dfsg emacsen-common emelfm2 eog g++ g++-4.8 gawk gcc gcc-4.8 ghc ghc-haddock gimp gimp-data gimp-help-common gimp-help-en gimp-help-es git git-core gitk git-man git-svn ibus ibus-gtk3:amd64 ibus-gtk:amd64 ibus-libpinyin ibus-pinyin ibus-sunpinyin ibus-table ibus-table-extraphrase ibus-table-wubi imagemagick imagemagick-common latex-beamer latex-cjk-all latex-cjk-chinese latex-cjk-chinese-arphic-bkai00mp latex-cjk-chinese-arphic-bsmi00lp latex-cjk-chinese-arphic-gbsn00lp latex-cjk-chinese-arphic-gkai00mp latex-cjk-common latex-cjk-japanese latex-cjk-japanese-wadalab latex-cjk-korean latex-cjk-thai latexdiff latexmk latex-sanskrit latex-xcolor less lyx lyx-common mail-notification make makedev mc mc-data meld memcached moc mutt mutter-common nodejs ntfs-3g ntpdate openjdk-7-jdk:amd64 openjdk-7-jre:amd64 openjdk-7-jre-headless:amd64 openssl pidgin pidgin-data pidgin-dev pidgin-libnotify python2.7 python python2.7-minimal python3 python3.4 python3.4-minimal python3-apport python3-apt python3-aptdaemon python3-aptdaemon.gtk3widgets python3-aptdaemon.pkcompat python3-brlapi python3-cairo python3-chardet python3-checkbox-ng python3-checkbox-support python3-commandnotfound python3-crypto python3-dbus python3-dbus.mainloop.qt python3-debian python3-defer python3-distupgrade python3-feedparser python3-gdbm:amd64 python3-gi python3-gi-cairo python3-httplib2 python3-icu python3-louis python3-lxml python3-mako python3-markupsafe python3-minimal python3-oauthlib python3-oneconf python3-pam python3-piston-mini-client python3-pkg-resources python3-plainbox python3-problem-report python3-pyatspi python3-pycurl python3-pyparsing python3-pyqt4 python3-requests python3-sip python3-six python3-software-properties python3-speechd python3-uno python3-update-manager python3-urllib3 python3-xdg python3-xkit python-appindicator python-apsw python-apt python-apt-common python-aptdaemon python-aptdaemon.gtk3widgets python-beautifulsoup python-bluez python-cairo python-chardet python-cherrypy3 python-chm python-commandnotfound python-crypto python-cssselect python-cssutils python-cups python-cupshelpers python-dateutil python-dbus python-dbus-dev python-debian python-debtagshw python-defer python-dirspec python-dnspython python-docutils python-feedparser python-gconf python-gdbm python-gi python-gi-cairo python-glade2 python-gnome2 python-gnomekeyring python-gobject-2 python-gobject python-gtk2 python-gtksourceview2 python-httplib2 python-ibus python-imaging python-jinja2 python-keybinder python-ldb python-libxml2 python-lockfile python-lxml python-markdown python-markupsafe python-mechanize python-minimal python-mysql.connector python-netifaces python-notify python-ntdb python-numpy python-oauthlib python-oneconf python-openssl python-pam python-paramiko python-pexpect python-pil python-piston-mini-client python-pkg-resources python-pyatspi python-pycurl python-pygments python-pyodbc python-pyorbit python-pyparsing python-pysqlite2 python-qt4 python-qt4-dbus python-renderpm python-reportlab python-reportlab-accel python-repoze.lru python-roman python-routes python-samba python-serial python-sip python-six python-smbc python-sphinx python-sqlite python-support python-talloc python-tdb python-tk python-twisted-bin python-twisted-core python-twisted-web python-ubuntu-sso-client python-utidylib python-vte python-webob python-wnck python-xapian python-xdg python-zeitgeist python-zope.interface 
apt-get install rhythmbox rhythmbox-data rhythmbox-mozilla rhythmbox-plugin-cdrecorder rhythmbox-plugin-magnatune rhythmbox-plugins rhythmbox-plugin-zeitgeist rsync rsyslog ruby ruby1.9.1 sbcl scrot smbc smbclient smbnetfs smplayer smplayer-themes smplayer-translations terminator tex4ht tex4ht-common tex-common tex-gyre texinfo texlive texlive-base texlive-bibtex-extra texlive-binaries texlive-doc-cs+sk texlive-doc-en texlive-doc-zh texlive-extra-utils texlive-fonts-extra texlive-fonts-extra-doc texlive-fonts-recommended texlive-fonts-recommended-doc texlive-font-utils texlive-formats-extra texlive-full texlive-games texlive-generic-extra texlive-generic-recommended texlive-humanities texlive-humanities-doc texlive-lang-african texlive-lang-arabic texlive-lang-cjk texlive-lang-cyrillic texlive-lang-czechslovak texlive-lang-english texlive-lang-european texlive-lang-french texlive-lang-german texlive-lang-greek texlive-lang-indic texlive-lang-italian texlive-lang-latin texlive-lang-other texlive-lang-polish texlive-lang-portuguese texlive-lang-spanish texlive-latex3 texlive-latex-base texlive-latex-base-doc texlive-latex-extra texlive-latex-extra-doc texlive-latex-recommended texlive-latex-recommended-doc texlive-luatex texlive-math-extra texlive-metapost texlive-metapost-doc texlive-music texlive-omega texlive-pictures texlive-pictures-doc texlive-plain-extra texlive-pstricks texlive-pstricks-doc texlive-publishers texlive-publishers-doc texlive-science texlive-science-doc texlive-xetex tilda tk tk8.6 tmux totem totem-common totem-mozilla totem-plugins transmission-common transmission-gtk ttf-adf-accanthis ttf-adf-gillius ttf-baekmuk ttf-bitstream-vera ttf-dejavu ttf-dejavu-core ttf-dejavu-extra ttf-indic-fonts-core ttf-punjabi-fonts ttf-ubuntu-font-family ttf-unfonts-core ttf-wqy-microhei ttf-wqy-zenhei udisks udisks2 unrar unzip vim-gtk vlc vsftpd w3m zip zsh 
apt-get install  build-essential   cmake make g++ libx11-dev libgl1-mesa-dev libglu1-mesa-dev libxrandr-dev libxext-dev freeglut3-dev freeglut3 freeglut3-dbg
# apt-get remove samba samba-common samba-common-bin samba-dsdb-modules samba-libs:amd64 samba-vfs-modules 

ubuntu的多媒体包

安装媒体解码器来播放 MP3、MPEG4 和其他格式媒体文件

如果你想播放媒体文件,如 MP3、MPEG4、AVI 等,你需要安装媒体解码器。由于各个国家的版权问题, Ubuntu 在默认情况下不会安装它。

作为个人,你可以使用 Ubuntu Restricted Extra 安装包很轻松地安装这些媒体编解码器。这将在你的 Ubuntu 系统安装媒体编解码器、Adobe Flash 播放器和微软 True Type 字体等。

你可以通过点击这个链接来安装它(它会要求在软件中心打开它),或者使用以下命令:

sudo apt install ubuntu-restricted-extras

滚动升级

GUI

update-manager --devel-release

CLI

$ sudo do-release-upgrade

$ lsb_release -a

升级到最新开发版

vim /etc/update-manager/release-upgrades文件,把里面的 Prompt=lts改为Prompt=normal

sudo do-release-upgrade -d

CDROM

$ sudo mount -t iso9660 -o loop ~/maverick-alternate-i386.iso /cdrom
$ sudo /cdrom/cdromupgrade

开发用工具安装

nodejs

gulp:

sudo npm install -g gulp 
sudo npm install -g gulp-clean gulp-jshint gulp-processhtml gulp-compass gulp-less gulp-concat gulp-uglify gulp-rename gulp-minify-css  gulp-file-include markdown gulp-template run-sequence

电源管理

常用的用户空间电源管理包。

  • tlp 默认的配置就不错/
  • acpid可扩展性更强

https://wiki.archlinux.org/index.php/Power_management

安全加固

及时更新

在 Ubuntu 和 Debian 上:

$ sudo apt update && sudo apt upgrade -y

在 Fedora、CentOS 或 RHEL:

$ sudo dnf upgrade

建立日常使用的特权用户

创建一个新的用户帐户。永远不要以root身份登录服务器,而是创建你自己的帐户 (用户),赋予它sudo权限,然后使用它登录你的服务器。

首先adduser创建一个新用户,然后通过将sudo组(-G)附加(-a) 到用户的组成员身份里,usermod -a -G sudo从而授予新用户帐户 sudo 权限。

上传你的 SSH 密钥

你应该使用 SSH 密钥登录到新服务器。

$ ssh-copy-id @ip_address

安全强化 SSH

接下来,进行以下三个更改:

  1. 禁用 SSH 密码认证
  2. 限制 root 远程登录
  3. 限制对 IPv4 或 IPv6 的访问

使用你选择的文本编辑器打开/etc/ssh/sshd_config并确保以下行:

PasswordAuthentication yesPermitRootLogin yes

改成这样:

PasswordAuthentication noPermitRootLogin no

接下来,通过修改AddressFamily选项将 SSH 服务限制为 IPv4 或 IPv6。 要将其更改为仅使用 IPv4(对大多数人来说应该没问题),请进行以下更改:

AddressFamily inet

重新启动 SSH 服务以启用你的更改。请注意,在重新启动 SSH 服务之前, 与服务器建立两个活动连接是一个好主意。有了这些额外的连接, 你可以在重新启动 SSH 服务出错的情况下修复所有问题。

在 Ubuntu 上:

$ sudo service sshd restart

在 Fedora 或 CentOS 或任何使用 Systemd 的系统上:

$ sudo systemctl restart sshd

启用防火墙

现在,你需要安装防火墙、启用防火墙并对其进行配置,以仅允许你指定的网络流量通过 。(Ubuntu 上的)简单的防火墙(UFW)是一个易用的 iptables 界面, 可大大简化防火墙的配置过程。

你可以通过以下方式安装 UFW:

$ sudo apt install ufw

默认情况下,UFW 拒绝所有传入连接,并允许所有传出连接。 这意味着服务器上的任何应用程序都可以访问互联网, 但是任何尝试访问服务器的内容都无法连接。 首先,确保你可以通过启用对 SSH、HTTP 和 HTTPS 的访问来登录:

$ sudo ufw allow ssh 
$ sudo ufw allow http 
$ sudo ufw allow https

然后启用 UFW:

$ sudo ufw enable

你可以通过以下方式查看允许和拒绝了哪些服务:

$ sudo ufw status

如果你想禁用 UFW,可以通过键入以下命令来禁用:

$ sudo ufw disable

你还可以(在 RHEL/CentOS 上)使用 firewall-cmd,它已经安装并集成到某些发行版中。

安装 Fail2ban

Fail2ban 是一种用于检查服务器日志以查找重复或自动攻击的应用程序。 如果找到任何攻击,它会更改防火墙以永久地或在指定的时间内阻止攻击者的 IP 地址。 你可以通过键入以下命令来安装 Fail2ban:

$ sudo apt install fail2ban -y

然后复制随附的配置文件:

$ sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

重启 Fail2ban:

$ sudo service fail2ban restart

这样就行了。该软件将不断检查日志文件以查找攻击。一段时间后, 该应用程序将建立相当多的封禁的 IP 地址列表。你可以通过以下方法查询 SSH 服务的当前状态来查看此列表:

$ sudo fail2ban-client status ssh

移除无用的网络服务

几乎所有 Linux 服务器操作系统都启用了一些面向网络的服务。 你可能希望保留其中大多数,然而,有一些你或许希望删除。 你可以使用 ss 命令查看所有正在运行的网络服务: (LCTT 译注:应该是只保留少部分,而所有确认无关的、无用的服务都应该停用或删除。 )

$ sudo ss -atpu

ss 的输出取决于你的操作系统。下面是一个示例,它显示 SSH(sshd)和 Ngnix(nginx) 服务正在侦听网络并准备连接:

tcp LISTEN 0 128 *:http *:* users:(("nginx",pid=22563,fd=7))
tcp LISTEN 0 128 *:ssh *:* users:(("sshd",pid=685,fd=3))

删除未使用的服务的方式因你的操作系统及其使用的程序包管理器而异。 要在 Debian / Ubuntu 上删除未使用的服务:

$ sudo apt purge

要在 Red Hat/CentOS 上删除未使用的服务:

$ sudo yum remove

再次运行ss -atup以确认这些未使用的服务没有安装和运行。