Showing posts with label 技術筆記. Show all posts
Showing posts with label 技術筆記. Show all posts

Nov 25, 2009

利用 rsa 登入 SSH Server

1. ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa): [按 Enter 使用預設值(建議)]
Enter passphrase: 輸入你的 Passphrase
Enter same passphrase again: 再一次輸入你的 Passphrase
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is: cc:e8:a9:da:a3:41:c6:a9:97:52:59:ef:0c:cf:45:b6 username@abc.com
2. scp ~/.ssh/*.pub 你欲登入的主機:~/.ssh/.
3. ssh 你欲登入的主機
4. cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
5. chmod 711 ~/.ssh
6. chmod 644 ~/.ssh/authorized_keys

發現,用 ubuntu 9.10 完成以上這些動作,就可以直接登入主機,不需在使用 ssh-agent


Reference:
  1. ssh keygen 免輸入密碼
  2. SSH 免密碼登入
  3. PuTTY 免密碼登入
  4. OpenSSH Public Key Authentication

Mar 30, 2009

Change TimeZone in Linux

sudo ln -s /usr/share/zoneinfo/Asia/Taipei /etc/localtime

ubuntu gusty to hardy

今天重開回到之前灌的 ubuntu ,本來想直接升級到 8.10 發現版本差太多,安裝時就會出問題,所以先升級到 hardy 就好,但開完機發現,鍵盤數字鍵無法使用,原來是我的鍵盤鍵被改成滑鼠 XD,可以使用 Ctrl+Shift+Num 切回數字鍵功能,剛剛在網路上查,原來是 X-Window 快速鍵

Feb 25, 2009

auto login by expect


#!/usr/bin/expect

spawn telnet ptt.cc
expect "請輸入代號,或以[guest]參觀,以[new]註冊:"
send "{Your Name}\n"
send "{Your Password}\n"

send "\n"

interact timeout 90 {send "s"}
exit

Feb 2, 2009

RADVD

前幾天測試使用RADVD來發送IPv6,只需 apt-get install radvd 但安裝時,/etc 下不會有config,需手動從 /usr/share/doc/radvd-doc/examples 中 Copy 到 /etc 下,起動 /etc/init.d/radvd start,此時可能會發生 IPv6 Forwoding 沒有設定,參考 Linux IPv6 HowTo 得知,echo "1" > /proc/sys/net/pv6/conf/default/forwarding 就可解決

以下是我使用簡單的 Config :
interface eth0
{
AdvSendAdvert on;

# This may be needed on some interfaces which are not active when
# radvd starts, but becomoe available later on; see man page for details.

# IgnoreIfMissing on;

#
# These settings cause advertisements to be sent every 3-10 seconds. This
# range is good for 6to4 with a dynamic IPv4 address, but can be greatly
# increased when not using 6to4 prefixes.
#

MinRtrAdvInterval 3;
MaxRtrAdvInterval 10;

#
# You can use AdvDefaultPreference setting to advertise the preference of
# the router for the purposes of default router determination.
# NOTE: This feature is still being specified and is not widely supported!
#
AdvDefaultPreference low;

#
# Disable Mobile IPv6 support
#
AdvHomeAgentFlag off;

#
# example of a standard prefix
#
prefix 2001:db8:1:0::/64
{
AdvOnLink on;
AdvAutonomous on;
AdvRouterAddr off;
};
};

Jan 21, 2009

yum的常用指令整理

最近因為工作的關係,需要用CentOS,但平時自已都是使用Debian/GNU or Ubuntu,對yum用起來一直很不習慣,稍為整理一下,常會使用的指令

yum update [套件1] [...] #用來更新套件,若後面不加任何的套件,則會更新所有系統目前已經安裝了的套件
yum install 套件1 [...] #用來安裝套件
yum upgrade [套件1] [...] #連一些過舊即將洮汰的套件也一起版本升級動作
yum remove 套件1 [...] #移除套件
yum clean [packages|headers|oldheaders|all]
yum list [updates|installed|extras]
yum check-update #檢查可以更新的套件
yum info [updates|installed|extras]
yum provides 套件1 [...] #列出套件提供哪些檔案
yum search [參數] #搜尋套件

Jan 20, 2009

[引用]redirect output from serial port

不過,我已經放了之前在那一個Blog找到的資料 XD

1. modify bios:
(1)Change BIOS settings /Server/Serial Console Features/BIOS Redirection Port to
[Serial port 1 or 2]
(2)change direct to modem

2. modify /boot/grub/menu.lst for suse
modify /boot/grub/grub.conf for red hat
console=ttyS0, 115200,vt100

3. modify /ect/inittab
c0:2345:respawn:/sbin/agetty ttyS0 19200 vt100

4. modify /etc/securetty
ttyS0

Jan 9, 2009

rename your network card by udev config

my os is debian 5.0 testing
~# dpkg -l | grep udev
ii udev 0.125-7 /dev/ and hotplug management daemon


# This file was automatically generated by the /lib/udev/write_net_rules
# program, probably run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.
# MAC addresses must be written in lowercase.

# PCI device 0x1106:0x3065 (via-rhine)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:05:5d:07:48:e5", NAME="eth2"

# PCI device 0x8086:0x1079 (e1000)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:04:23:a5:a4:b5", NAME="eth1"

# PCI device 0x8086:0x1079 (e1000)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:04:23:a5:a4:b4", NAME="eth0"


define via-rhine is eth0, e1000(dual port) are eth1 and eth2

# PCI device 0x1106:0x3065 (via-rhine)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:05:5d:07:48:e5", NAME="eth0"

# PCI device 0x8086:0x1079 (e1000)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:04:23:a5:a4:b4", NAME="eth1"

# PCI device 0x8086:0x1079 (e1000)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:04:23:a5:a4:b5", NAME="eth2"

Nov 6, 2008

Compiler Kernel

簡單做個筆記

1. 從 www.kernel.org 下載最新版 kernel source
2. cp /boot/config-2.6.xx /usr/src/{new-version-kernel}/.config //如已安裝相近版本的kernel,直接使用它的 config-2.6.xx 在修改就好了
3. sudo make oldconfig
4. sudo make menuconfig
4.1 加入版本名稱 // Gerneral setup -> Local version 如 : -blue119-01
5. sudo make
6. sudo make modules_install
7. sudo make install
8. cd /boot; sudo mkinitramfs -o initrd.img-2.6.xx-blue119-01 2.6.xx-blue119-01 // 2.6.xx-blue119-01 的目錄名稱在 /lib/modules/
9. sudo vi /boot/grub/menu.lst //加新新的kernel

PS : 也可以使用 make-kpkg來制作 kernel,安裝與移除方便很多 :)
make-kpkg binary --rootcmd=fakeroot --revision=修訂版本 --append-to-version=核心擴充版本

reference link:
http://www.howtoforge.com/howto_linux_kernel_2.6_compile_debian

Oct 30, 2008

USB vendor id and device id

可以從 /var/lib/usbutils/usb.ids 得知,vendor id & device id

Oct 29, 2008

strace

  1. strace - A very powerful troubleshooting tool for all Linux users
  2. Fun with strace and the GDB Debugger
  3. 5 simple ways to troubleshoot using Strace
  4. reducing Requests-Setup-Costs
  5. strace 命令用法

rtorrent.rc 備份

# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
min_peers = 40
max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
min_peers_seed = 10
max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
max_uploads = 3

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 10

encoding_list = UTF-8

# Default directory to save the downloaded torrents.
directory = ./

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = ./session

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=./watch/*.torrent
#schedule = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
#schedule = low_diskspace,5,60,close_low_diskspace=100M

# Stop torrents when reaching upload ratio in percent,
# when also reaching total upload in bytes, or when
# reaching final upload ratio in percent.
# example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
#schedule = ratio,60,60,"stop_on_ratio=200,200M,2000"

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
port_range = 6890-6999

# Start opening ports at a random position within the port range.
port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
#check_hash = no

# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext

# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10

screenrc 備份

caption always "%{= wk} %{= KY} [%n]%t @ %H %{-} %= %{= KR} %l %{-} | %{= KG} %Y-%m-%d %{-} "
hardstatus alwayslastline " %-Lw%{= Bw}%n%f %t%{-}%+Lw %=| %0c:%s "

# some environment setting
vbell off
autodetach on
startup_message off
shell -$SHELL
dfscrollback 5000
defencoding utf8
#
# # buttom status bar
#caption always “%{=u .G} %-w%<%{=ub .y}%n %t%{=u .G}%+w ”
#hardstatus alwaysignore
#hardstatus alwayslastline “%{= .K} [%l]%<%=%{= .W}@%H %=%{= .y} %Y/%m/%d%{= .m} %C %A”
#
# # C + left : prev
# # C + right : next
bindkey “^[[1;5C” next
bindkey “^[O5C” next
bindkey “^[[C” next
bindkey “^[[1;5D” prev
bindkey “^[O5D” prev
bindkey “^[[D” prev
#
# # C-a b : encoding big5
# # C-a u : encoding utf8
bind b encoding big5 utf8
bind u encoding utf8 utf8
bind j encoding eucjp utf8
#
# # C-b $num : move current window to number $num
bind -c move 0 number 0
bind -c move 1 number 1
bind -c move 2 number 2
bind -c move 3 number 3
bind -c move 4 number 4
bind -c move 5 number 5
bind -c move 6 number 6
bind -c move 7 number 7
bind -c move 8 number 8
bind -c move 9 number 9
bindkey “^b” command -c move
#
# # F12 : fast kill
bindkey “^[[24~” kill

Oct 27, 2008

JFFS2 筆記

JFFS2的特性
  • 其斷電可靠度
  • 在MTD裝置上實做耗損平衡(wear leveling). 可以確保flash 上所有的區塊具有一致的使用率, 因此可以平衡每個區塊的損耗程度
  • 在MTD裝置上實做資料壓縮(data compression). 除了節省空間外, 在使用資料前先將它解壓到RAM上.不過, jffs2不能使用XIP(就地執行eXecute In Place)
  • 有實做垃圾收集(garbage collection). 它可以確保你的應用程式不會成長到到埴滿整個檔案系統.也就是寫入前會先檢查檔案系統的可用空間

Create jffs2 root file system
1. mkfs.jffs2 -d ./rootfs -o rootfs.bin -e 0x40000 --pad=0x02000000
2. file rootfs.bin
rootfs.bin: Linux jffs2 filesystem data little endian


Mount JFFS2 by MTD
1. modprobe jffs2
2. modprobe mtdblock
3. modprobe mtdram
4. dd if=rootfs.bin of=/dev/mtdblock0
5. mkdir /mnt/flash
6. mount -t jffs2 /dev/mtdblock0 /mnt/flash

Save as .....
1. dd if=/dev/mtdblock0 of=./your-modified-fs-image.bin

Dec 1, 2007

[備份] OpenEmbedded

忘了是不是自已寫的筆記 XD

Setting up the toolchain and doing a build Directory Structure
mkdir -p /stuff/build/conf
cd /stuff/

Obtaining BitBake
cd /stuff/
svn co http://svn.berlios.de/svnroot/repos/bitbake/branches/bitbake-1.8/ bitbake

Updating bitbake
cd /stuff/bitbake; svn info
cd /stuff/bitbake; svn update

Obtaining OpenEmbedded
wget http://www.openembedded.org/snapshots/OE.mtn.bz2
bunzip2 OE.mtn

Install Monotone 0.32
http://monotone.ca/downloads/0.32/

mtn --db=/stuff/OE.mtn pull monotone.openembedded.org org.openembedded.dev
mtn --db=/stuff/OE.mtn checkout --branch=org.openembedded.dev
mtn --db=/stuff/OE.mtn checkout --branch=org.openembedded.dreambox

mtn --db=/stuff/OE.mtn pull monotone.openembedded.org org.openembedded.dev
mtn --db=/stuff/OE.mtn pull monotone.openembedded.org org.openembedded.dreambox

cd /stuff/org.openembedded.dev && mtn update
cd /stuff/org.openembedded.dreambox && mtn update

Create local configuration
cd /stuff/
cp org.openembedded.dev/conf/local.conf.sample build/conf/local.conf
vi build/conf/local.conf

Setup the environment
$ export PATH=/stuff/bitbake/bin:$PATH
$ export BBPATH=/stuff/build:/stuff/org.openembedded.dev

Start building
$ bitbake nano

May 8, 2007

VI小技巧,加速學習Python

於vimrc中加入
map <f2> :!clear;python %
寫完python後,直接按F2就可看結果 :)