Archive for the tag 'linux'

把ssh-key加到遠端電腦

chenpc November 16th, 2009

ssh-copy-id -i .ssh/id_rsa.pub root@remotehost

上班族ssh tunnel求生手冊

chenpc October 20th, 2009

常常阿,在上班,但是想打個BBS,上個plurk,開個msn聊聊天。但是卻擔心網管監控你的一舉一動。於是可以透過ssh tunnel來把自己的連線加密,這樣就不會被看光光啦。

範例1:
在公司,透過外面的電腦當proxy,連到外面。

ssh -NfD 8888 remote_ip
-N : 不執行任何命令
-f : 在背景執行
-D : 建socks5 的proxy

這時候,瀏覽器和msn在socks 5 proxy設定的欄位填上localhost:8888 。
連出去的連驗就是加密,並且是穿過remot_ip的連線。

範例2:
在公司,透過外面的電腦連BBS。

ssh -NfL 2323:bbs.gamer.com.tw:23 remote_ip
-L : 將local port 轉向

telnet localhost 2323 就可以連到巴哈,而且是加密的。
也可用PCManx連localhost 2323也是一樣的意思。

範例3:
有時候假日,想要連回公司加個班。
但是公司是NAT,所以沒辦法這樣作。
可以運用TCP雙向傳輸的特性來辦到這件事。

ssh -NfR 2222:localhost:22 remote_ip
-R : 將remote port轉向

這時候,只要跑到remote_ip的機器上面
ssh localhost -p 2222
就會跑到在NAT後面,公司的機器。
簡單說就是開後門啦!

Move ext3 to ext4

chenpc May 8th, 2009

tune2fs -O extents,uninit_bg,dir_index /dev/sdxx

Fix vmware-server-console keyboard map problem

chenpc February 17th, 2009

echo “xkeymap.nokeycodeMap = true” >> ~/.vmware/config

將linux 一般分割區轉成RAID1

chenpc December 13th, 2008

Set normal partition to RAID1

Boot into Live! CD

fdisk /dev/sdb  ; partition sdb3 as partition type ‘fd’
mount /dev/sda3 /mnt/gentoo
mdadm -C /dev/md0 -l 1 -n 2 missing /dev/sdb3
mkdir /mnt/raid
mount /dev/md0 /mnt/raid
rsync -avH –progress /mnt/gentoo /mnt/raid
fdisk /dev/sda  ; partition sda3 as partition type ‘fd’
madm /dev/md0 -a /dev/sda3
edit fstab /mnt/raid/etc/fstab to new root partition ‘/dev/md0′

reboot and set mdadm daemon as well.

釋放 lsof 的力量

chenpc December 13th, 2008

emerge lsof

常常,目錄umount不掉。
# umount /mnt/cdrom
umount: /mnt/cdrom: device is busy
umount: /mnt/cdrom: device is busy

看看到底是誰在用阿!
# lsof | grep /mnt/cdrom
bash  6453   larry  cwd  DIR  7,0  2048  1856 /mnt/cdrom
su    15774  root   cwd  DIR  7,0  2048  1856 /mnt/cdrom

常常,看到一些port不知道是誰開的。
# lsof -i TCP:25
OMMAND   PID USER   FD   TYPE DEVICE SIZE NODE NAME
master  17408 root   12u  IPv4 632942       TCP localhost:smtp (LISTEN)

master是甚麼阿?
# ps auxww|grep master
root 17408 0.0 0.0 5220 1516 ? Ss 06:19 0:00 /usr/lib/postfix/master

他parent是誰?
# lsof -R -i TCP:25
COMMAND   PID PPID USER   FD   TYPE DEVICE SIZE NODE NAME
master  17408    1 root   12u  IPv4 632942       TCP localhost:smtp (LISTEN)
PPID = 1,看一下祖譜吧。
# pstree 1
init–6*[agetty]
–amd
–cron
–master—pickup
–      –qmgr
–mysqld—16*[{mysqld}]
–ntpd
–portmap
–rpc.mountd
–rpc.rstatd
–rpc.statd
–squid—squid—30*[redirect.pl]
-               ??unlinkd
–2*[sshd???sshd---tcsh]
–sshd—2*[sshd--sshd---tcsh]
-      –sshd—sshd—tcsh—pstree
–syslog-ng
–udevd
–ypbind—2*[{ypbind}]

更新SA之後的後續動作

chenpc December 13th, 2008

這裡用Gentoo Linux更新openssl為例:
當openssl出現GLSA的通知信之後,我們跑到機器上更新。

emerge -u1 openssl
-u:是指update
-1:不要加到world list裡面(one shot)

更新完之後,用lsof查看需要重開的服務。

sudo lsof | grep ‘DEL.*lib’ | cut -f 1 -d ‘ ‘ | sort -u
->
這行會列出只用到一些lib已被移除的程式。
irssi
lpd
master
pure-ftpd
qmgr
ssh
sshd

上面這些程式如果你不知道他們是什麼,可以用qfile去看他屬於哪些套件
qfile sshd
->net-misc/openssh (/usr/sbin/sshd)

如果是pure-ftpd,apache,lighttd這些屬於系統服務的程式
請記得要重開才算完成SA更新。

Vixie Cron in Linux

chenpc December 13th, 2008

Vixie cron in FreeBSD is different from Linux.

BSD:
/usr/bin/crontab <– setuid
/var/cron/tabs <–only root can change it
“tabs” is a file which contains user field and program location.

Linux
/usr/bin/crontab <– nosetuid
/var/spool/cron/crontabs <– user can change it
“crontabs” is a “DIR” which contains user’s crontab file.

crontab file format:
/var/spool/cron/crontabs/chenpc
===============================
*/5 * * * * command
===============================

Q:How to make vixie-cron work in Linux ?
A:Join “cron” group. (gpasswd -a chenpc cron

Default permission in Linux:
drwxr-x— 4 root cron /var/spool/cron
drwx-wx–T 2 root crontab /var/spool/cron/crontabs

We should change to:
drwxr-xr-x 4 root cron /var/spool/cron
drwx-wx-wt 2 root crontab /var/spool/cron/crontabs

I had change permission in linux0~6
and commit new post_base.sh to do so.

ext2,ext3,ext4dev and xfs和他的們好朋友

chenpc December 13th, 2008

[EXT{2,3,4}]
badblocks:
檢查壞軌,其實不限定一定要是ext*的fs。

tune2fs:
改變fs的一些設定,比方說reserve的比例。
在實驗ext4dev的時候,要用tune2fs打開test_fs這個功能。

mkfs.ext4dev:
最近的版本有把ext4的fsck tool放進去了。

chattr:
類似FreeBSD下面的chflags。
可以在原本的read,write,exec,sticky,setuid屬性之外增加延伸屬性。
比方說檔案不可刪除…等等。
不過這個東西不是OS本身實做的,而是要依賴File System的實做。
所以ext*有這個功能,xfs並沒有。

lsattr:
查看chattr所設定的屬性。

mkfs.ext{2,3,4}:
將partition format成ext{2,3,4}格式。

如何將ext2 -> ext3 -> ext4dev ?
首先要先unmount。
tune2fs -j /dev/sda1 ##加journal的ext2就是ext3
tune2fs -E test_fs -O extents /dev/sda1 ##把test功能和extents功能打開就是ext4了。
tune2fs -m 0 ##保留0%給root

[XFS]
xfs_quota:
xfs的quota和其他fs比較不一樣。
他並不是在目錄下放一個quota.user當作紀錄擋。
xfs的quota是實作在日誌系統裡面。
所以quotacheck的指令對他無效。
他不需要作quotacheck,因為只要xfs被正確mount起來。
他就確保quota的正確性,也就是說開機不需要檢查半天
看看quota對不對。
xfs_freeze:
有些時候我們不能去複製一個”活”的檔案系統。
因為他一直在變動,所以我們沒辦法確保複製前後是否一致。
這時候除了umount之外,還有”結凍”這個方法。

xfs_copy,xfsdump,or xfsrestore:
同字面的意思,需在umount或freeze下面使用。

xfs_check,xfs_repair:
檢查一致性,會在不正常關機之後有機會會用到。

fsck.xfs:
這是虛招,其實沒有用。
只是要配合fsck的機制而已,遇到有問題他會在mount時警告你。
自行用上面兩個程式檢查,個人經驗是遇到xfs_repair其實很
可能是硬碟根本壞軌了。

xfs_mkfile:
快速的生出一個特定大小的檔案,這招會比dd快很多。

Quick Guilde to gnuplot

chenpc June 18th, 2008

plot -> 2D plot
splot -> 3D plot
gnuplot> splot “data” -> splot a file named “data”
data format:
x y value
x y value

plot mesh :
gnuplot> set dgrid3d 30,30
gnuplot> set hidden3d
gnuplot> plot “data”

ref:
http://phi.sinica.edu.tw/aspac/reports/94/94002/plot-6.html
http://t16web.lanl.gov/Kawano/gnuplot/plot3d2-e.html
http://lidebin.wordpress.com/2006/09/20/gnuplot-curve-fitting/
http://www.duke.edu/~hpgavin/gnuplot.html

Next »