aliyun折腾记录

缘起

最早淘宝购买的一台vps突然抽风,联系运维也没结果,一怒之下就断续了,之后半年就处于空档期。最近被推送了一个aliyun轻量化服务器的广告,1G cpu+1G ram+40G disk+1T 流量只要24元/月,还算实惠,就买了一台。总结如下,aliyun只适合玩玩,不适合做梯子。

 

第一部分

系统

aliyun原装系统

个人比较喜欢debian,所以选择的系统镜像是debian8.9。目前debian已经发展到debian9,对于debian8的维护已经停止,所以使用apt update时只能用jessie,其他例如jessie-updates都会出错。

deb https://xxx.xxx/debian/ jessie main contrib non-free 这行不会出错

deb https://xxx.xxx/debian/ jessie-updates main contrib non-free 这行会出错

出错信息

W: Failed to fetch http://ftp.uk.debian.org/debian/dists/jessie-updates/InRelease  Unable to find expected entry 'main/source/Sources' in Release file (Wrong sources.list entry or malformed file)

 

 从Jessie升级到Stretch

所以安装完aliyun提供的debian8.9后,第一件要做的事就是升级到debian9,步骤如下:

1. su - root
2. apt update && apt upgrade && apt dist-upgrade
3. vim /etc/apt/sourecs.list,将jessie替换为stretch(s/jessie/stretch/g)。注:aliyun镜像提供的apt源是写在/etc/apt/sources.list.d/sources.aliyun-*.list中,可以删除或修改
4. apt update && apt upgrade 这是最小化升级
5. apt dist-upgrade 这是完全升级
6. apt autoremove && apt clean 升级完成后卸载不需要的软件包和清理升级缓存
7. reboot
8. lsb_release -a 查看debian版本

 

 Debian软件源格式说明

字段1 字段2                            字段3    字段4
deb  http://mirrors.163.com/debian/  wheezy   main non-free contrib

 

字段1 --- 软件包格式

deb --------------- 安装二进制包

deb-src ---------- 安装源代码包

 

 

字段2 --- 源路径,可以有以下类型

http://

ftp://

cdrom:/

file:/

https://  注:使用https需要额外安装apt-transport-https

 

 

字段3 --- 版本号+附加限定

示例

jessie-security

jessie-updates

jessie-proposed

jessie-backports


版本号

oldstable --- 代表上一个稳定版本

stable --- 代表当前稳定版本

testing --- 正在测试的版本

sid(unstable) --- 正在开发的版本,无稳定保证

wheezy --- Debian7的版本代号

jessie --- Debian8的版本代号

stretch --- Debian9的版本代号

附加限定

Security - Important Security Updates. 

Updates - Recommended Updates. 

Proposed - Pre-released Updates. 

Backports - Unsupported Updates. 

 

字段4

main     Debian里最基本及主要且符合自由软件规范的软件 ( packages )。
contrib     这里头软件虽然可以在 Debian 里头运作,即使本身属于自由软件但多半却是相依于非自由 ( non-free ) 软件。
non-free   不属于自由软件范畴的软件。
non-us     这个分类里头的软件都来自非美国地区,当中可能有牵扯到专利、加密..等等问题。
marillat     对应 Christian Marillat 的软件仓库,包括mplayer, transcode等。
rareware   对应 rarewares.org 的软件仓库, 包括很多音效程序,如lame, musepack, beep media player等。
ustc      对应 debian@ustc 维护的一些软件包,如 mule-gbk, gaim-openq, scim, stardict dicts, patched xpdf, irssi, xmms。
java       对应 Blackdown java。包括 j2re, j2sdk ,mozilla java plugin。
firefly      对应打过firefly补丁的包,包括 fontconfig mozilla mozilla-firefox pango1.0 qt-x11-free xft
misc      对应其它无分类的包,包括 nvidia-kernel, winex3, rox, chmsee等

 

 

 

增加sudo权限

默认的普通用户没有sudo权限,按照如下步骤增加sudo权限。

1. 可以修改/etc/sudoers,添加如下语句,xxx代表需要加sudo的普通账号。

# User privilege specification
root  ALL=(ALL:ALL) ALL
xxx  ALL=(ALL) ALL

 

 2. 按照官方文档建议,不要直接修改/etc/sudoers,官方文档如下。

# As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on
# installation of the package now includes the directive:
#
#       #includedir /etc/sudoers.d
#
# This will cause sudo to read and parse any files in the /etc/sudoers.d
# directory that do not end in '~' or contain a '.' character.
#
# Note that there must be at least one file in the sudoers.d directory (this
# one will do), and all files in this directory should be mode 0440.
#
# Note also, that because sudoers contents can vary widely, no attempt is
# made to add this directive to existing sudoers files on upgrade.  Feel free
# to add the above directive to the end of your /etc/sudoers file to enable
# this functionality for existing installations if you wish!
#
# Finally, please note that using the visudo command is the recommended way
# to update sudoers content, since it protects against many failure modes.
# See the man page for visudo for more information.
#

  替代方案是在/etc/sudoers.d目录下增加文件,文件名的要求是不能以~结尾和不能包含,文件的内容如下,xxx代表需要加sudo的普通账号。

xxx  ALL=(ALL) ALL

 

配置SSH登陆

因为是自己玩的,所以想配置SSH只能自己登陆,方法如下。

1. 限制用户

a. 白名单

在 /etc/ssh/sshd_config 配置文件中设置 AllowUsers 选项,(配置完成需要重启 SSHD 服务)格式如下:

AllowUsers    aliyun test@192.168.1.1            
# 允许 aliyun 和从 192.168.1.1 登录的 test 帐户通过 SSH 登录系统。

 

b. 黑名单

在/etc/ssh/sshd_config配置文件中设置DenyUsers选项,(配置完成需要重启SSHD服务)格式如下:   

DenyUsers    zhangsan aliyun    #Linux系统账户        
# 拒绝 zhangsan、aliyun 帐户通过 SSH 登录系统

 

2. 限制IP

除了可以禁止某个用户登录,我们还可以针对固定的IP进行禁止登录,linux 服务器通过设置 /etc/hosts.allow 和 /etc/hosts.deny 这个两个文件,hosts.allow许可大于hosts.deny,可以允许或者限制某个或者某段IP地址远程 SSH 登录服务器。

1. vim /etc/hosts.allow, 添加

sshd:192.168.0.1:allow  #允许 192.168.0.1 这个 IP 地址 ssh 登录
sshd:192.168.0.1/24:allow #允许 192.168.0.1/24 这段 IP 地址的用户登录

 

 未完待续

posted @ 2019-05-22 12:31  memphise  阅读(259)  评论(0编辑  收藏  举报