分類: Linux

顯示 Ubuntu Linux 伺服器管理與使用技巧

在 Ubuntu Linux 中有個指令叫做 ubuntu-server-tip,這個程式可以隨機提供管理伺服器上的技巧,這對於伺服器的管理者而言,若是想要多增進 Linux 管理的功力,這是個不錯的學習管道。

ubuntu-server-tip 這個程式是包含在 fortunes-ubuntu-server 這個套件中,若要使用要先安裝:

sudo apt-get install fortunes-ubuntu-server -y

安裝完成後,直接執行:

ubuntu-server-tip

它會隨機顯示一條使用技巧,以下是一些例子。

讓 SSH 登入的使用者只能執行特定指令:

To restrict ssh logins to certain commands, have a look at the ForceCommand directive (see “man sshd_config”).


利用 tail 指令查看紀錄檔的最後幾行的技巧:

Use ‘tail -f file’ to watch a log file as messages get appended, and use ‘tail -100 file’ to change the count of lines read from the file.

使用 which 查詢某個指令所在位置:

Use the “which” command to find if an executable is in your path, and if it is, where you can find the file. e.g. ‘which nano’

使用 yes 指令自動輸入 ‘y’:

Tired of repeatedly pressing ‘y’ through some shell process (e.g. fsck)? Try the ‘yes’ command. ‘man yes’ for more info.

PostgreSQL 使用技巧:

If you are using a PostgreSQL database, use “ptop” to monitor real time usage.

Bash 中的迴圈寫法:

A for loop in bash syntax: ‘for i in * ; do echo $i ; done’.

若要編譯程式,必須安裝 build-essential 套件:

If you need to compile a piece of software, you may need to install the build-essential package. Use ‘sudo apt-get install build-essential’.

這些使用技巧雖然都是英文寫的,不過都很短,對於英文不好的人應該是不至於造成負擔。

安裝完成之後,預設在使用者登入時就會自動顯示一條使用技巧,就像這樣:

這樣每天登入 Ubuntu Linux 伺服器時,就順便學習一個管理或使用技巧,個人感覺這是很實用的指令。

一般 Linux 中的登入訊息是寫在 /etc/motd,而 ubuntu-server-tip 會將使用技巧自動加在其中,如果想調整登入顯示使用技巧的設定,可以修改 /etc/default/ubuntu-server-tips 這個設定檔,他的內容大概就像這樣:


# /etc/default/ubuntu-server-tips
# Enable random tip displayed in the /etc/motd at login
MOTD=1

# Disable random tip displayed in the /etc/motd at login
# MOTD=0

預設 MOTD=1 就是在 motd 中顯示使用技巧,若要關閉這個功能,則設為 MOTD=0 即可。

G. T. Wang

個人使用 Linux 經驗長達十餘年,樂於分享各種自由軟體技術與實作文章。

Recent Posts

光陽 KYMCO GP 125 機車接電發動、更換電瓶記錄

本篇記錄我的光陽 KYMCO ...

1 年 ago

[開箱] YubiKey 5C NFC 實體金鑰

本篇是 YubiKey 5C ...

2 年 ago

[DIY] 自製竹火把

本篇記錄我拿竹子加上過期的苦茶...

2 年 ago