這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
linux:linux_server_hacks_100_tips [2007/04/01 17:37] wenpei 60 ngrep |
linux:linux_server_hacks_100_tips [2008/03/28 21:42] (目前版本) wenpei |
||
---|---|---|---|
行 181: | 行 181: | ||
+ | ===== 61 nmap ===== | ||
+ | 辨識作業系統 | ||
+ | nmap -O abc.tw | ||
+ | |||
+ | 辨識服務的版本 | ||
+ | nmap -sV abc.tw -p 22 | ||
+ | |||
+ | ===== 64 ntop ===== | ||
+ | apt-get install ntop | ||
+ | |||
+ | 開成 daemon,可透過網頁連 port 3000 提供統計資料 | ||
+ | ntop -d | ||
+ | |||
+ | ===== 66 ssh-keygen ===== | ||
+ | 產生一對金鑰,途中可考慮要不要輸入 passphrase | ||
+ | ssh-keygen -t rsa | ||
+ | |||
+ | 產生公鑰:~/.ssh/id_rsa.pub 和私鑰:~/.ssh/id_rsa,將公鑰放入想要遠端的主機 | ||
+ | $ scp ~/.ssh/id_rsa.pub [username]@[server.name]:~/.ssh/ | ||
+ | $ ssh [username]@[server.name] | ||
+ | $ cat ~/.ssh/id_rsa >> ~/.ssh/authorized_keys | ||
+ | |||
+ | 若私鑰遭竊,別人即可輕易登入。 | ||
+ | |||
+ | ==== 遠端命令 ==== | ||
+ | 一個簡單的 ssh-to | ||
+ | <code> | ||
+ | #!/bin/sh | ||
+ | ssh `basename $0` $* | ||
+ | </code> | ||
+ | |||
+ | $ ln -s ssh-to a.sars.tw | ||
+ | $ ln -s ssh-to b.sars.tw | ||
+ | |||
+ | 執行指令即可直接列出遠端主機的狀態 | ||
+ | $ ./a.sars.tw uptime | ||
+ | |||
+ | ===== 68 ssh-agent ===== | ||
+ | $ eval `ssh-agent` | ||
+ | $ ssh-add | ||
+ | |||
+ | /etc/ssh/ssh_config | ||
+ | ForwardAgent yes | ||
+ | |||
+ | ===== 70 X over ssh ===== | ||
+ | 透過 X11 forwardng 執行遠端的程式 | ||
+ | |||
+ | 修改 sshd_config | ||
+ | X11Forwarding yes | ||
+ | |||
+ | $ ssh -X host | ||
+ | |||
+ | ===== 71 ssh forward ===== | ||
+ | ssh -f -N -L110:mailserver:110 -l user mailserver | ||
+ | |||
+ | ===== 72 環境設定檔同步 ===== | ||
+ | movein.sh:(tar 的 -h 表在遠端產生的是普通檔案,而非 link ) | ||
+ | <code> | ||
+ | #!/bin/sh | ||
+ | |||
+ | if [ -z "$1" ]; then echo "Usage: `basename $0` hostname" | ||
+ | exit | ||
+ | fi | ||
+ | |||
+ | cd ~/.skel | ||
+ | tar zhcf - . | ssh $1 "tar zpvxf -" | ||
+ | </code> | ||
+ | |||
+ | 在家目錄下整理需要複製的設定檔 | ||
+ | $ mkdir .skel | ||
+ | $ cd .skel | ||
+ | $ ln -s ../.bashrc .bashrc | ||
+ | $ ln -s /etc/vim/vimrc .vimrc | ||
+ | $ mkdir .ssh | ||
+ | $ cd .ssh | ||
+ | $ ln -s ../../.ssh/id_rsa.pub authorized_keys2 | ||
+ | |||
+ | ===== 75 色彩化日誌 ===== | ||
+ | rcg 使用 Term::ANSIColor 將符合條件的字串改成特定色彩 | ||
+ | |||
+ | less -r 將 ESC sequence 解釋成彩色效果 | ||
+ | |||
+ | 正規式: | ||
+ | \d+\.\d+\.\d+\.\d+\. # IP 位址的表示法 | ||
+ | ^(J|F|M|A|S|O|N|D)\w\w (\d|)\d # 日期字串 | ||
+ | \b\d\d:\d\d:\d\d\b # 時間字串 | ||
+ | |||
+ | ===== 88 Apache Index full files name ===== | ||
+ | IndexOptions FancyIndexing NameWidth=* | ||
+ | IndexOptions FancyIndexing VersionSort HTMLTable NameWidth=* |