這已經在公司用了好久了,不是什麼了不起的應用
來這裡筆記一下吧
詳細的使用看 manpage 第一段就明確的告訴你
ssh-keygen generates, manages and converts authentication keys
for ssh(1). ssh-keygen can create RSA keys for use by
SSH protocol version 1 and RSA or DSA keys for use by SSH
protocol version 2. The type of key to be generated is specified
with the -t option. If invoked without any arguments, ssh-keygen
will generate an RSA key for use in SSH protocol 2 connections.
預設不自作聰明的帶參數的話會是 SSH protocol 2 可使用的 RSA key。
但是 RSA非對稱式加密 有些歷史因素,個人認為在 1024 bits 以下都很危險..
所以個人還是偏好使用 DSA演算法
廢話不多說來產生 key
rellik@desktop(01:05:08)[~]$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/rellik/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/rellik/.ssh/id_dsa.
Your public key has been saved in /home/rellik/.ssh/id_dsa.pub.
大概按兩三次 Enter 鍵就結束了
而在工作環境下我的 HOME 目錄又是使用 NFS 掛載到每一台機器上的
這有個好處可以讓我快速的游移在多台機器中不需要打帳號密碼節省了
很多敲鍵盤的時間。
作法是在 $HOME/.ssh 目錄底下建立一個 authorized_keys
然後把 $HOME/.ssh/id_dsa.pub (記得是 public key 呀)貼到
authorized_keys 裡,權限 600 ,這樣就可以利用 nfs 快速的在
機器間遊走了 。
最後忘了說,Debian liked 的系統強烈建議安裝 openssh-blacklist
這個套件 ......, 不清楚的人可參考之前的文章 Debian的openssl漏洞
個人心情和 Linux / FreeBSD 等技術
2008/10/12
錯誤訊息:$HOME/.dmrc檔案已被忽略
今天不知道安裝了什麼軟體以後,之後打完帳號密碼登入都會
出現以下警告『使用者的 $HOME/.dmrc 檔案已被忽略。這會
使得預設作業階段及語系無法儲存。該檔案必須由只用者所擁
有及權限為644。使用者 $HOME 目錄必須由使用者擁有並且
不允許其他使用者寫入。』
既然錯誤訊息都提示了有關於權限,就來檢查一下吧
$ ls -al ~/.dmrc
-rw------- 1 rellik rellik 48 2008-10-12 00:14 .dmrc
還真的不是644 . .不知道在幹啥的時候被改掉,快改回來
$ chmod 644 .dmrc
$ ls -al ~/.dmrc
-rw-r--r-- 1 rellik rellik 48 2008-10-12 00:14 .dmrc
另外檢查HOME目錄權限
$ cd /home
$ ls -l
drwxrwxrwx 63 rellik rellik 4096 2008-10-12 00:21 rellik
這個更誇張了. . .權限 777,我哪時有改過這東西
╯-____-)╯~═╩════╩═~
$ chmod 700 rellik
$ ls -l
drwx------ 63 rellik rellik 4096 2008-10-12 00:21 rellik
改完後測試看看,重新登出再登入,果然沒警告訊息了
出現以下警告『使用者的 $HOME/.dmrc 檔案已被忽略。這會
使得預設作業階段及語系無法儲存。該檔案必須由只用者所擁
有及權限為644。使用者 $HOME 目錄必須由使用者擁有並且
不允許其他使用者寫入。』
既然錯誤訊息都提示了有關於權限,就來檢查一下吧
$ ls -al ~/.dmrc
-rw------- 1 rellik rellik 48 2008-10-12 00:14 .dmrc
還真的不是644 . .不知道在幹啥的時候被改掉,快改回來
$ chmod 644 .dmrc
$ ls -al ~/.dmrc
-rw-r--r-- 1 rellik rellik 48 2008-10-12 00:14 .dmrc
另外檢查HOME目錄權限
$ cd /home
$ ls -l
drwxrwxrwx 63 rellik rellik 4096 2008-10-12 00:21 rellik
這個更誇張了. . .權限 777,我哪時有改過這東西
╯-____-)╯~═╩════╩═~
$ chmod 700 rellik
$ ls -l
drwx------ 63 rellik rellik 4096 2008-10-12 00:21 rellik
改完後測試看看,重新登出再登入,果然沒警告訊息了
2008/10/07
雙系統所遇到的GRUB開機問題
先說明一下我的環境,兩顆硬碟,在BIOS底下的資訊
Primary Master 是 ST380013A 我安裝的是 Windows XP
Professional , 而 Primary Slave 是HDT722516DLAT80,
這個是安裝Debian。
== == == == == == == == == ==我是分隔線 == == =
在Debian安裝過程最後會需要選擇安裝 GRUB , 由於之前安裝
ETCH 的經驗是把GRUB安裝在 Primary Master 之上,也就是寫入
XP 那顆硬碟的 MBR中,這樣子做的好處是方便我辨識硬碟!
因為 GRUB 和 Linux 在裝置檔的辨識上是不一樣的, 先說說大家
熟悉的 Linux,Primary Master 會辨識成 /dev/hda , Primary Slave
則是 /dev/hdb在正常以 Primary Master (xp) 開機的情況底下,
GRUB會將第一個搜尋到的硬碟辨識為 /dev/hd0,這裡會暫時得
到一個結論 /dev/hda 對應到的是 /dev/hd0
ps.{這裡就很容易造成一般User的混亂,以為 /dev/hda就是對應
成/dev/hd0 ,而 /dev/hdb就是對應成 /dev/hd1, 但是實際上
GRUB的開機代號。} 和排線上的Master 、 Slave (Linux上 /dev/hda
、/dev/hdb)沒有任何關係
而且我將 GRUB 安裝在 /dev/hda 的 MBR 這麼作有個缺點,就是
1、我一定要在BIOS選擇以 Primary Master 開機;
2、而且 Master和 Slave 兩顆硬碟缺一不可。
當我把 Master (Windows) 拔下來時,Slave 會因為 MBR 的消失無
法把開機程序轉交給 GRUB 這個 boot loader造成我的linux無法開機
;反之把 Slave (Linux)拔下來時,GRUB這個 boot loader 的消失也
無法把開機程序轉交給 Windows loader來執行換成我的 XP不能開機。
PS.關於 linux x86 的開機流程可參考此網頁
由於我的主機板可以從 BIOS 調整從 Primary Master 或是 Primary
Slave 開機,所以相較於之前硬碟缺一不可的不便利(我偶而會拆
卸硬碟),這次安裝Lenny 的時候我決定將 MBR 安裝在 Slave 的
MBR 中,以後就用 Slave 上的 GRUB 來決定開進 Linux 還是
Windows。所以我的 Slave 變成 了開機硬碟 。這樣子也
解決了我之前硬碟缺一不可的窘境。
由於 Linux將 Slave 視為 /dev/hdb ,所以在預設情況下安裝的 GRUB 寫入
menu.lst 設定如下
root (hd1,0)
savedefault
makeactive
chainloader +1
但光是上面這樣還不足以正常的開入 Windows XP , 在
GRUB的 0.97 Manual提到:
被修改錯誤的狀況。
參考文件
GRUB 0.97 Manual
Primary Master 是 ST380013A 我安裝的是 Windows XP
Professional , 而 Primary Slave 是HDT722516DLAT80,
這個是安裝Debian。
== == == == == == == == == ==我是分隔線 == == =
在Debian安裝過程最後會需要選擇安裝 GRUB , 由於之前安裝
ETCH 的經驗是把GRUB安裝在 Primary Master 之上,也就是寫入
XP 那顆硬碟的 MBR中,這樣子做的好處是方便我辨識硬碟!
因為 GRUB 和 Linux 在裝置檔的辨識上是不一樣的, 先說說大家
熟悉的 Linux,Primary Master 會辨識成 /dev/hda , Primary Slave
則是 /dev/hdb在正常以 Primary Master (xp) 開機的情況底下,
GRUB會將第一個搜尋到的硬碟辨識為 /dev/hd0,這裡會暫時得
到一個結論 /dev/hda 對應到的是 /dev/hd0
ps.{這裡就很容易造成一般User的混亂,以為 /dev/hda就是對應
成/dev/hd0 ,而 /dev/hdb就是對應成 /dev/hd1, 但是實際上
GRUB的開機代號。} 和排線上的Master 、 Slave (Linux上 /dev/hda
、/dev/hdb)沒有任何關係
而且我將 GRUB 安裝在 /dev/hda 的 MBR 這麼作有個缺點,就是
1、我一定要在BIOS選擇以 Primary Master 開機;
2、而且 Master和 Slave 兩顆硬碟缺一不可。
當我把 Master (Windows) 拔下來時,Slave 會因為 MBR 的消失無
法把開機程序轉交給 GRUB 這個 boot loader造成我的linux無法開機
;反之把 Slave (Linux)拔下來時,GRUB這個 boot loader 的消失也
無法把開機程序轉交給 Windows loader來執行換成我的 XP不能開機。
PS.關於 linux x86 的開機流程可參考此網頁
由於我的主機板可以從 BIOS 調整從 Primary Master 或是 Primary
Slave 開機,所以相較於之前硬碟缺一不可的不便利(我偶而會拆
卸硬碟),這次安裝Lenny 的時候我決定將 MBR 安裝在 Slave 的
MBR 中,以後就用 Slave 上的 GRUB 來決定開進 Linux 還是
Windows。所以我的 Slave 變成 了開機硬碟 。這樣子也
解決了我之前硬碟缺一不可的窘境。
由於 Linux將 Slave 視為 /dev/hdb ,所以在預設情況下安裝的 GRUB 寫入
menu.lst 設定如下
title Debian GNU/Linux, kernel 2.6.26-1-686title Microsoft Windows XP Professional
root (hd1,0)
kernel /vmlinuz-2.6.26-1-686 root=/dev/hdb3 ro
initrd /initrd.img-2.6.26-1-686
title Debian GNU/Linux, kernel 2.6.26-1-686 (single-user mode)
root (hd1,0)
kernel /vmlinuz-2.6.26-1-686 root=/dev/hdb3 ro single
initrd /initrd.img-2.6.26-1-686
注意到了 (hd1,0) 在 GRUB的解釋下是第二個找到的硬碟
(開機 Slave 的是第一個找到的,應該是 (hd0,0)才對),
所以Lenny一開始安裝完重開後馬上就會出現錯誤訊息無法開
進系統,當然這個時候只要在錯誤的那行按 「e」編輯成 (hd0,0)
再按 「b」即可正常的開機,再進入 /boot/grub/menu.lst
編輯存檔即可。
os.不知道為什麼會出現這種奇妙的小錯誤。
順便將 Windows 的部份修正如下
root (hd1,0)
savedefault
makeactive
chainloader +1
但光是上面這樣還不足以正常的開入 Windows XP , 在
GRUB的 0.97 Manual提到:
If you have installed DOS (or Windows) on a non-first hard disk, you have to use the
disk swapping technique, because that OS cannot boot from any disks but the first one.
The workaround used in GRUB is the command map (see map), like this:
grub> map (hd0) (hd1)2008/10/9 update: 以 aptitude 更新至新的 kernel 後也會發生 menu.lst
grub> map (hd1) (hd0)
所以請利用 disk swapping的技術吧! 正確的設定如下
title Microsoft Windows XP Professional
map (hd0) (hd1)
map (hd1) (hd0)
root (hd1,0)
savedefault
makeactive
chainloader +1
這樣子就能以 Slave 當成開機硬碟又能順利開啟 Windows囉。
被修改錯誤的狀況。
參考文件
GRUB 0.97 Manual
2007/09/03
2007/08/20
fail2ban這程式
無意間翻到威力寰這篇讓我心動了一下
過去只針對sshd安裝了denyhosts,但鑒於有安裝apache
等服務還是覺得不太安全來試裝了一下fail2ban,
在安裝前先把iptables給裝好
Debian ETCH
$sudo aptitude install iptables fail2ban
開始設定fail2ban
$sudo vi /etc/fail2ban/jail.local (拷貝/etc/fail2ban/jail.conf)
[DEFAULT]
ignoreip = 127.0.0.1 (空白鑑隔開填入要信任的ip位置)
bantime = -1 (設成了永久ban掉..)
maxretry = 20 (設定20次重試~)
[ssh]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 20
[apache]
enabled = true
port = http
filter = apache-auth
logpath = /var/log/apache*/*access.log
maxretry = 20
設定完後重跑
$sudo /etc/init.d/fail2ban restart
收工~
參考資料
Willie's Blog
過去只針對sshd安裝了denyhosts,但鑒於有安裝apache
等服務還是覺得不太安全來試裝了一下fail2ban,
在安裝前先把iptables給裝好
Debian ETCH
$sudo aptitude install iptables fail2ban
開始設定fail2ban
$sudo vi /etc/fail2ban/jail.local (拷貝/etc/fail2ban/jail.conf)
[DEFAULT]
ignoreip = 127.0.0.1 (空白鑑隔開填入要信任的ip位置)
bantime = -1 (設成了永久ban掉..)
maxretry = 20 (設定20次重試~)
[ssh]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 20
[apache]
enabled = true
port = http
filter = apache-auth
logpath = /var/log/apache*/*access.log
maxretry = 20
設定完後重跑
$sudo /etc/init.d/fail2ban restart
收工~
參考資料
Willie's Blog
2007/05/05
squid 效能等注意事項!
關於 filesystem
squid 對於 RAID 的擊中率特別的差勁 = =,尤其是 RAID
4 / 5簡單了說就是不建議使用 RAID
關於SMP
Squid is a single process application and can not make use of SMP。
If you want to make Squid benefit from a SMP system you
will needto runmultiple instances of Squid and find a way to
distribute yourusers on thedifferent Squid instances just as
if you had multiple Squid boxes.
and does notbenefit from dual-CPU configuration
*大意是...squid這隻程式無法在多 cpu 的系統獲得更多好處
,但是多個cpu的確能夠讓 unix 系統在額外執行程式時更流暢...*
關於OS安裝
Running Squid on separate drives to that which your OS is
running is often a very good idea
*將OS和squid快取分開安裝在不同的disk上是不錯的*
Generally seek time is what you want to optimize for Squid,
or moreprecisely the total amount of seeks/s your system
can sustain.This is why it is better to have your cache_dir
spread over multiple smallerdisks than one huge drive
(especially with SCSI).
*把 cache_dir 分派在多個而容量較小的disk效能會勝過單一
容量大的硬碟*
ex: 單一2GB*5個會比單一10GB的要好
If your system is very I/O bound, you will want to have
both yourOS and log directories running on separate drives.
*系統I/O頻繁時最好把系統和 log 與 disk cache分開,另外
最好是一個partition 就只放一個 cache_dir *
如何找出在 cache 中最大的物件
# sort -r -n +4 -5 access.log | awk '{print $5, $7}' | head -25
如何把cache清除乾淨?
# squid -k shutdown
# echo . . > /cache1/swap.state (每個cache都要)
Squid.conf中cache_mem代表的是?
cache_mem不代表 squid 所使用記憶體的最大值,它只能表示
需要用多少記憶體留住 " hot " (點擊率高)的檔案。
Squid需要多少記憶體?
1GB的cache_dir大約佔用10MB的 ram ,但是在64位元的 server
上會更多
*簡言之,記憶體插曹插滿就對了 = =*
沒有多餘記憶體的話,要如何降低記憶體使用
1.使用不同的malloc library ,例如GNU malloc 或是 dlmalloc
2.降低 squid.conf 設定檔中 cache_mem 的量 (Reducing this
parameterwill not significantly affect performance, but you may
recieve somewarnings in cache.log if your cache is busy)
3. Turn the memory_pools off in the config file. This causes
Squid togive up unused memory by calling free() instead of
holding on to thechunk for potential, future use. Generally
speaking, this is a bad ideaas it will induce heap fragmentation.
Use memory_pools_limit instead.
4. 降低設定檔中的 cache_swap . This will reduce the number
of objectsSquid keeps. Your overall hit ratio may go down a little,
but your cache will perform significantly better.
*某些malloc不支援超過2GB的記憶體,包括dlmalloc,當記憶體
大於2GB時則只能使用到2GB*
參考資料
squid的wiki
- Linux
- Reiserfs
reiserfs3 works just fine, it's recommended that
you mount with noatime and notail options, and
for theperformance freaks put the journal on a
different spindle
- ext3
- another fine blend, the defaults filesystem
- creation parameters are just good for squid
- - watch out for the number of inodes - squid
- cached objects are usually about 12-16 kb in
- size, make sure you have enough.
-
- another fine blend, the defaults filesystem
- ext2
- well, ext2 is a venerable good filesystem. But
- do youreally want to wait for hours while your
- FS is being checked?
- well, ext2 is a venerable good filesystem. But
- Reiserfs
- Solaris
- UFS
- UFS is the old Solaris File System, which good and stable.
- Use "noatime" as mount option.
- UFS is the old Solaris File System, which good and stable.
- ZFS
- Use ZFS, if you want really high performance for your
- Squid Cache. ZFS is included in Solaris beginning with
- Solaris 10.Release 6/06. Use "noatime" as mount option.
- Use ZFS, if you want really high performance for your
- UFS
squid 對於 RAID 的擊中率特別的差勁 = =,尤其是 RAID
4 / 5簡單了說就是不建議使用 RAID
關於SMP
Squid is a single process application and can not make use of SMP。
If you want to make Squid benefit from a SMP system you
will needto runmultiple instances of Squid and find a way to
distribute yourusers on thedifferent Squid instances just as
if you had multiple Squid boxes.
Having two CPUs is indeed nice for running other CPU
intensive tasks onthe same server as the proxy, such as if
you have a lot of logs and need torun various statistics
collections during peak hours.
and does notbenefit from dual-CPU configuration
*大意是...squid這隻程式無法在多 cpu 的系統獲得更多好處
,但是多個cpu的確能夠讓 unix 系統在額外執行程式時更流暢...*
關於OS安裝
Running Squid on separate drives to that which your OS is
running is often a very good idea
*將OS和squid快取分開安裝在不同的disk上是不錯的*
Generally seek time is what you want to optimize for Squid,
or moreprecisely the total amount of seeks/s your system
can sustain.This is why it is better to have your cache_dir
spread over multiple smallerdisks than one huge drive
(especially with SCSI).
*把 cache_dir 分派在多個而容量較小的disk效能會勝過單一
容量大的硬碟*
ex: 單一2GB*5個會比單一10GB的要好
If your system is very I/O bound, you will want to have
both yourOS and log directories running on separate drives.
*系統I/O頻繁時最好把系統和 log 與 disk cache分開,另外
最好是一個partition 就只放一個 cache_dir *
如何找出在 cache 中最大的物件
# sort -r -n +4 -5 access.log | awk '{print $5, $7}' | head -25
如何把cache清除乾淨?
# squid -k shutdown
# echo . . > /cache1/swap.state (每個cache都要)
Squid.conf中cache_mem代表的是?
cache_mem不代表 squid 所使用記憶體的最大值,它只能表示
需要用多少記憶體留住 " hot " (點擊率高)的檔案。
Squid需要多少記憶體?
1GB的cache_dir大約佔用10MB的 ram ,但是在64位元的 server
上會更多
*簡言之,記憶體插曹插滿就對了 = =*
沒有多餘記憶體的話,要如何降低記憶體使用
1.使用不同的malloc library ,例如GNU malloc 或是 dlmalloc
2.降低 squid.conf 設定檔中 cache_mem 的量 (Reducing this
parameterwill not significantly affect performance, but you may
recieve somewarnings in cache.log if your cache is busy)
3. Turn the memory_pools off in the config file. This causes
Squid togive up unused memory by calling free() instead of
holding on to thechunk for potential, future use. Generally
speaking, this is a bad ideaas it will induce heap fragmentation.
Use memory_pools_limit instead.
4. 降低設定檔中的 cache_swap . This will reduce the number
of objectsSquid keeps. Your overall hit ratio may go down a little,
but your cache will perform significantly better.
*某些malloc不支援超過2GB的記憶體,包括dlmalloc,當記憶體
大於2GB時則只能使用到2GB*
參考資料
squid的wiki
2007/05/03
cruel unix
摘錄
You now, unix is a cruel operating system, sometimes parent kills its children, and what it worse, it sometimes turns them into zombies.
詳見pavelmachek
You now, unix is a cruel operating system, sometimes parent kills its children, and what it worse, it sometimes turns them into zombies.
詳見pavelmachek
訂閱:
文章 (Atom)