0%

ubuntu的一些配置

16年入了台搬瓦工上的传家宝,一年/20刀,好好珍惜和爱护

免密登录

在本机生成 ssh key 公钥私钥

1
2
3
ssh-keygen -C mykey

ssh-keygen.exe -C mykey # windows

会提示你生成的文件的地址, 并且让你输入密码, 你不要输入密码, 直接回车, 这样你就得到了一对 ssh-key

1
2
3
id_rsa 是私钥 自己保存 不要给别人

id_rsa.pub 是公钥, 是要到处使用的

把本机生成的 id_rsa.pub 添加到服务器 /root/.ssh/authorized_keys 文件中

用 root 用户登录到服务器, 创建 .ssh 目录,创建authorized_keys文件

1
2
3
cd /root
mkdir .ssh
touch authorized_keys

编辑 authorized_keys 文件, 把刚才生成的 id_rsa.pub 文件里面的内容粘贴进去并保存退出, 这里可以粘贴多个 key, 一行一个

1
nano .ssh/authorized_keys

禁用密码登录

1
nano /etc/ssh/sshd_config

把里面的 PasswordAuthentication 改成 no 值

重启 ssh 服务

1
service ssh restart

ufw 防火墙

安装
1
sudo apt install ufw
允许和阻止端口
1
2
3
4
5
6
7
# 允许
ufw allow 22
ufw allow 80
ufw allow 443

# 拒绝
ufw deny 8080
默认规则
1
2
3
4
5
# 默认拒绝所有接入
ufw default deny incoming

# 默认接受所有输出
ufw default allow outgoing
查看状态
1
ufw status verbose
开启
1
ufw enable
关闭
1
ufw disable

linux oh-my-zsh

安装 oh-my-zsh 配置(方便你使用命令行的配置)

1
2
3
apt-get install

wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh

服务器中文编码问题

编辑下面的文件

1
nano /etc/environment

加入下面的内容, 保存退出

1
2
LC_CTYPE="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

systemctl 是针对于 systemd的管理工具 ,直接管理的对象称之为单元 units

查看

查看当前系统载入的单元

1
systemctl list-units

查看所有单元

1
systemctl list-unit-files

查看包含某个关键词的单元文件

1
systemctl list-unit-files | grep mail

只查看服务类型的单元

1
systemctl list-unit-files --type=service

查看某个服务是否是运行状态

1
systemctl is-active 服务名

查看某个服务是否是开机启动

1
systemctl is-enabled 服务名

查看某个服务的详细状态(添加 sudo -l 命令可以查看全部的信息)

1
systemctl status 服务名
管理(需要管理员权限)

尝试安装一个邮件服务

1
sudo apt install sendmail -y

启动

1
sudo systemctl start 服务名

停止

1
sudo systemctl stop 服务名

开机自启

1
2
sudo systemctl enable 服务名
sudo systemctl disable 服务名

重启与重新载入(优先选择)

1
2
sudo systemctl restart 服务名
sudo systemctl reload 服务名

禁止服务启动,解除禁止服务启动

1
2
sudo systemctl mask 服务名
sudo systemctl unmask 服务名

安装飞机

alias xx = ‘ss’

更新系统
1
2
3
sudo apt update

sudo apt upgrade
安装 pip
1
sudo apt install python3-pip
安装 xx
1
2
pip3 install https://github.com/shadowsocks/shadowsocks/archive/master.zip

创建配置文件,并修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sudo mkdir /etc/shadowsocks

sudo nano /etc/shadowsocks/config.json

# 修改 config.json

{
"server":"::",
"server_port":8989,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"mypassword",
"timeout":300,
"method":"aes-256-cfb",

}

配置 Systemd 管理 xx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 新建管理文件并打开

sudo nano /etc/systemd/system/shadowsocks-server.service

# 粘贴以下配置文件

[Unit]
Description=Shadowsocks Server
After=network.target

[Service]
ExecStart=/usr/local/bin/ssserver -c /etc/shadowsocks/config.json
Restart=on-abort

[Install]
WantedBy=multi-user.target

设置自启动 xx
1
2
3
4
5
6
7
8
# 启动

sudo systemctl start shadowsocks-server

# 设置开机启动

sudo systemctl enable shadowsocks-server

随便记些命令

ssh 和 scp
1
2
3
4
5
6
7
8
9
10
11
12
# scp

scp -P 29337 -r app root@ip:/tmp

# scp执行WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!错误解决

1, 查看家目录下的.ssh/know_hosts文件
2, 删除对应的失效的客户端 ip
cat ~/.ssh/known_hosts

# ssh
ssh -p 29337 root@你的ip
Linux 查找文件、文件夹
1
2
3
4
5
6
7
# 查找tomcat7文件夹所在的位置

find / -name 'tomcat7' -type d

# 查找server.xml文件的位置

find / -name 'server.xml' -print