不免要從新配置一臺服務器。這裏以一個 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>
參考: