不免要从新配置一台服务器。这里以一个 Bandwagon 的为例,简单的记录一下。linux
那边安装了系统以后会提供 IP 地址,SSH 端口号,还有 root 用户的密码。git
$ ssh root@<server-ip> -p <ssh-port>
而后输入了 root 密码就能够登录了。github
登录上以后先添加本身的用户shell
# adduser <your-name>
先随便输入一个密码,用户信息之类的按本身状况填写。apache
这样建立的用户是带用户目录的,不像 useradd
那样要加参数才行(useradd
是底层的函数,不推荐使用)。还会拷贝 /etc/skel
下的内容,里面能够放 .bashrc
之类的东西。基础的配置,好比默认 shell 是在 /etc/adduser.conf
中设置的,默认就是 bash。flask
删除用户也很简单,用 deluser
,一样这个是 userdel
的友好版本。下面的命令会同时把那个用户的 home 目录删掉。(更多用法去 man deluser
,要学着去 man
啊,虽然一开始会有些看不懂。)ubuntu
# deluser --remove-home <name>
设置 sudo 权限segmentfault
SSH 登录 & 免密码登录安全
禁止 SSH 密码登录bash
禁止 root 用户 SSH 登录
通常不直接拿 root 用户来用,而是给本身的用户加一下 sudo 权限。关键实在 /etc/sudoers
文件上。
# User privilege specification root ALL=(ALL:ALL) ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL
由于有了 sudo 组,因此把用户加到 sudo 组就行了。
# adduser <your-name> sudo
可是每次输入密码又很麻烦,且以后会把用户 SSH 登录的密码登录封掉,因此下面修改下 /etc/sudoers
文件,用 visudo
:
%sudo ALL=(ALL:ALL) NOPASSWD:ALL
参考:
sudo - How can I add a new user as sudoer using the command line? - Ask Ubuntu
关于用户组看这里:linux - Is there a command to list all Unix group names? - Stack Overflow
有了 SSH 登录以后就不在须要在登录的时候输入密码了。说简单点就是把本身的 xxx.pub
里面的内容放到 ~/.ssh/authorized_keys
文件中。例子以下:
$ mkdir /home/apps/.ssh $ echo <paste-your-key-here> > /home/apps/.ssh/authorized_keys
$ chown -R apps:apache /home/apps/.ssh $ chmod 700 /home/apps/.ssh $ chmod 600 /home/apps/.ssh/authorized_keys
参考:
Password-less logins in The Flask Mega-Tutorial, Part XVII: Deployment on Linux (even on the Raspberry Pi!) - miguelgrinberg.com
在这个文件里面有不少的相关的设置 /etc/ssh/sshd_config
,下面列举出几个和此次相关的:
RSAAuthentication yes PubkeyAuthentication yes #AuthorizedKeysFile %h/.ssh/authorized_keys # To enable empty passwords, change to yes (NOT RECOMMENDED) PermitEmptyPasswords no PermitRootLogin no PasswordAuthentication no Port 29831
RSAAuthentication
与 PubkeyAuthentication
有关系,可是实际用到的是后者,请看参考二。Key 固然就是放在 %h/.ssh/authorized_keys
下面,RSA 和 DSA 的均可以的样子。
PermitEmptyPasswords
是否容许空密码登录,能够看到用户是能够有空密码的状态的,可是有的应用会不容许空密码用户使用。详见参考一。这里不想让用户用密码登录,因此就设置成 no。
PermitRootLogin
设置成 no 禁止 root 用户登录。
PasswordAuthentication
设置成 no 禁止用户用密码登录。
Port
是 SSH 登录的 Port,通常设置一个不是默认的来提升一点安全性(彷佛是这样)。
记得 $ sudo service ssh reload
来让设置生效。
参考:
# passwd -d <username> # passwd -l <username>
前者是删掉密码使用户处于空密码状态,后者是锁掉用户的密码,使须要密码验证的操做不能正常进行。详见参考一。
参考:
先安装:
$ sudo apt-get install zsh
而后交给 Oh My Zsh 来配置:
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
$ sudo chsh -s /bin/zsh <user-name>
参考: