Skip to content

Instantly share code, notes, and snippets.

@willwhui
Last active September 29, 2018 00:27
Show Gist options
  • Save willwhui/75446223a7da65c494fa8c1fe7a8b626 to your computer and use it in GitHub Desktop.
Save willwhui/75446223a7da65c494fa8c1fe7a8b626 to your computer and use it in GitHub Desktop.
在sentris.net的vps上配置新用户
在sentris.net的vps上配置新用户
@willwhui
Copy link
Author

willwhui commented Jun 27, 2017

增加一个用户,然后设置它为sudoer(在sudoer目录下增加一个配置文件)。

平时就用这个用户登录好了。

sudo useradd -m username (才能创建出user的home)
sudo passwd username (创建密码)
sudo usermod -aG sudo username (允许sudo)

发现:

  • 原以为要把它加入到root组才能搞高权限操作,其实并不需要

@willwhui
Copy link
Author

willwhui commented Jun 27, 2017

ssh的Port参数为其他端口,减少被攻击的次数

修改/etc/ssh/sshd_config:
在Port 22下面增加类似下面这一行:
Port xxxxx

我们先保留原22端口,避免防火墙配置屏蔽了其他端口,导致无法ssh回去
然后重启ssh
service ssh restart
确认可以 ssh -p xxxxx username@xxx.xxx.xxx.xxx 成功后,再删掉sshd_config中的Port 22
记得service ssh restart

此时lastb看一下,貌似没有人搞我了。

@willwhui
Copy link
Author

willwhui commented Jun 27, 2017

新建的user ssh上去之后方向键变为乱码

echo $SHELL
查看当前的shell是/bin/sh
需要改为/bin/bash
sudo chsh命令不工作
直接修改/etc/passwd

sudo vi /etc/passwd

在新建的user那一行(通常在最后)的末尾增加"/bin/bash"
保存后,登出ssh,再重新登入ssh
好了。

@willwhui
Copy link
Author

willwhui commented Jun 27, 2017

vi的方向键和backspace不能正常工作

按照这里提到的方法1进行修改即可:
修改/etc/vim/vimrc.tiny
把set compatible
改成set nocompatible
并增加一句set backspace=2

@willwhui
Copy link
Author

willwhui commented Jun 27, 2017

此时系统资源占用情况(运行top)
%Cpu(s): 5.2 us, 5.7 sy, 0.0 ni, 87.6 id, 0.1 wa, 0.0 hi, 1.4 si, 0.0 st
KiB Mem : 131072 total, 16892 free, 45988 used, 68192 buff/cache

@willwhui
Copy link
Author

willwhui commented Jun 27, 2017

配置完ss,使用gcm加密协议后的系统资源占用情况(运行top)
%Cpu(s): 5.0 us, 6.4 sy, 0.0 ni, 83.9 id, 3.2 wa, 0.0 hi, 1.4 si, 0.0 st
KiB Mem : 131072 total, 34496 free, 86860 used, 9716 buff/cache

@willwhui
Copy link
Author

willwhui commented Jun 27, 2017

ssh掉线时间太短

参见这里
sudo vi /etc/ssh/sshd_config
增加
ClientAliveInterval 30 #30秒的心跳
ClientAliveCountMax 100 # 跳100次(50分钟)
需要重新登入ssh

@willwhui
Copy link
Author

willwhui commented Jun 30, 2017

创建swap文件

按照这里的说明
采取快速创建的方式,并启动时加载
文章中提到,如果是VPS,应该将swappiness降低到0,减少交换的机会以避免运行过慢。
但是,服务商禁止了swapon功能

@willwhui
Copy link
Author

willwhui commented Oct 11, 2017

修改命令行提示符颜色

参见这里

@willwhui
Copy link
Author

修改命令行提示符字符串长度

参见这里

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment