2008年07月26日 星期六
iwl3945 on Debian
原来在debian下一直使用ipw3945驱动无线网卡,可是自从升到2.6.24以上内核以后,ipw3945就不能用了,内核提供了iwl3945模块来驱动。可是不知道为什么有好长时间不能从无线路由得到地址,也就是连不上无线网络,由于前段时间太忙,也没把这件事放在心上,使用网线连接凑乎了一段时间。今天实在无聊,就把它折腾出来了。
在折腾过程中,装了linux-wlan-ng,事实证明根本不需要,linux内核本身的东西就基本足够了。
系统版本:Debian testing 2.6.25-2-686
需要安装的软件包:firmware-iwlwifi
配置文件/etc/network/interfaces
iface wlan0 inet dhcp
pre-up ip link set wlan0 up
wireless-essid dlink
wireless-ap any
我用的路由器名称是dlink,根据实际情况可改作其他的。由于我的路由器没有使用加密验证之类的东东,所以没有其他配置,如需要可参考安装wpasupplicant。
ip命令在软件包iproute中。
2007年08月20日 星期一
Kile 和 kdvi之间的正向与反向搜索
正向搜索:在Kile中将闪烁光标放置到相应代码位置后,点击菜单栏上的ForwardDVI图标,可直接跳转到dvi文件的对应位置。
依次点击Kile菜单,Settings->Configure Kile...->Tools+Build,将LaTeX的配置选择为Modern。
反向搜索:在使用kdvi查看dvi时,使用鼠标中键点击dvi文件的某一位置,在Kile中闪烁光标会自动跳转到tex源代码的相应位置。
依次点击kdvi菜单,Settings->Configure KDVI...->DVI Specials,选择编辑器为Kile。
2007年07月20日 星期五
Sierra Wireless AirCard 555 for Debian Linux
这几天在使用联通的掌中宽CDMA无线上网卡,但是只提供了Windows下面的驱动程序。Linux下面的驱动得自己生成。
网卡型号:Sierra Wireless AirCard 555R
我的系统,Debian Linux testing
Kernel,Linux debian 2.6.21-2-686 SMP
创建并编辑下面两个文件:
创建/etc/pcmcia/aircard555.conf:
debian:/etc/pcmcia# more aircard555.conf
card "Sierra Wireless AirCard 555"
manfid 0x0192, 0xa555
cis "cis/aircard555.dat"
bind "serial_cs"
创建/etc/pcmcia/cis/aircard555.cis
debian:/etc/pcmcia/cis# more aircard555.cis
dev_info
no_info
attr_dev_info
EEPROM 250ns, 512b
manfid 0x013f, 0x0710
funcid serial_port
vers_1 7.0, "Sierra Wireless", "AirCard 555", "A555", "Rev 1"
config base 0x0700 mask 0x0073 last_index 0x03
cftable_entry 0x20 [default]
io 0x03f8-0x03ff [lines=3] [8bit] [range]
irq mask 0x3fbc [level]
cftable_entry 0x21
io 0x02f8-0x02ff [lines=3] [8bit] [range]
cftable_entry 0x22
io 0x03e8-0x03ef [lines=3] [8bit] [range]
cftable_entry 0x23
io 0x02e8-0x02ef [lines=3] [8bit] [range]
cftable_entry 0x24
io 0x0000-0x0007 [lines=3] [8bit]
然后应该生成文件aircard555.dat,命令如下:
debian:/etc/pcmcia/cis# pack_cis -o aircard555.dat aircard555.cis
但是,我的系统里面的pack_cis程序有问题,所以我是直接从网上下载的,你可以直接从这里下载aircard555.dat文件,拷贝到相应目录即可。
debian:/etc/pcmcia/cis# dmesg -c
debian:/etc/pcmcia/cis#
这是插入网卡,听到两声beep,
debian:/etc/pcmcia/cis# dmesg
pccard: PCMCIA card inserted into slot 0
pcmcia: registering new device pcmcia0.0
0.0: ttyS0 at I/O 0x3f8 (irq = 3) is a 16550A
可以看到系统已将网卡关联到/dev/ttyS0,在你的系统上有可能设备有所不同。
然后,可以使用pppconfig配置连接。
pppconfig
Main Menu:
Create Create a connection
Provider Name:
aircard
Configure Nameservers (DNS):
(*) Dynamic Use dynamic DNS
Authentication Method for aircard:
CHAP Crypto Handshake Auth Protocol
User Name:
card
Password:
card
Speed:
115200
Pulse or Tone:
(*) Tone
Phone Number:
#777
Choose Modem Config Method
Manually Select Modem Port
/dev/ttyS0
"Properties of aircard"
Please select the property you wish to modify, select "Cancel" to go back
Number #777 Telephone number
User card ISP user name
Password card ISP password
Speed 115200 Port speed
Com /dev/ttyS0 Modem com port
Method CHAP Authentication method
Advanced Advanced Options
Finished Write files and return to main menu.
Previous Return to previous menu
Quit Exit this utility
连接网络:
使用pon或者poff连接或者断开网络。
debian:/etc/pcmcia/cis# pon aircard
debian:/etc/pcmcia/cis# tail /var/log/messages -n 30
Jul 20 17:01:04 debian kernel: 0.0: ttyS0 at I/O 0x3f8 (irq = 3) is a 16550A
Jul 20 17:11:02 debian pppd[17058]: pppd 2.4.4 started by root, uid 0
Jul 20 17:11:03 debian chat[17062]: abort on (BUSY)
Jul 20 17:11:03 debian chat[17062]: abort on (NO CARRIER)
Jul 20 17:11:03 debian chat[17062]: abort on (VOICE)
Jul 20 17:11:03 debian chat[17062]: abort on (NO DIALTONE)
Jul 20 17:11:03 debian chat[17062]: abort on (NO DIAL TONE)
Jul 20 17:11:03 debian chat[17062]: abort on (NO ANSWER)
Jul 20 17:11:03 debian chat[17062]: abort on (DELAYED)
Jul 20 17:11:03 debian chat[17062]: send (ATZ^M)
Jul 20 17:11:03 debian chat[17062]: expect (OK)
Jul 20 17:11:03 debian chat[17062]: ATZ^M^M
Jul 20 17:11:03 debian chat[17062]: OK
Jul 20 17:11:03 debian chat[17062]: -- got it
Jul 20 17:11:03 debian chat[17062]: send (ATDT#777^M)
Jul 20 17:11:03 debian chat[17062]: expect (CONNECT)
Jul 20 17:11:03 debian chat[17062]: ^M
Jul 20 17:11:03 debian chat[17062]: ATDT#777^M^M
Jul 20 17:11:03 debian chat[17062]: CONNECT
Jul 20 17:11:03 debian chat[17062]: -- got it
Jul 20 17:11:03 debian chat[17062]: send (\d)
Jul 20 17:11:04 debian pppd[17058]: Serial connection established.
Jul 20 17:11:04 debian pppd[17058]: Using interface ppp0
Jul 20 17:11:04 debian pppd[17058]: Connect: ppp0 <--> /dev/ttyS0
Jul 20 17:11:09 debian pppd[17058]: CHAP authentication succeeded:
Jul 20 17:11:09 debian pppd[17058]: CHAP authentication succeeded
Jul 20 17:11:10 debian pppd[17058]: local IP address 211.145.37.188
Jul 20 17:11:10 debian pppd[17058]: remote IP address 220.192.0.22
Jul 20 17:11:10 debian pppd[17058]: primary DNS address 220.192.0.130
Jul 20 17:11:10 debian pppd[17058]: secondary DNS address 220.192.8.58
debian:/etc/pcmcia/cis# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:5363 errors:0 dropped:0 overruns:0 frame:0
TX packets:5363 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1122730 (1.0 MiB) TX bytes:1122730 (1.0 MiB)
ppp0 Link encap:Point-to-Point Protocol
inet addr:211.145.37.188 P-t-P:220.192.0.22 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:72 (72.0 b) TX bytes:87 (87.0 b)
然后就可以上网啦!
debian:/etc/pcmcia/cis# poff aircard
debian:/etc/pcmcia/cis# tail /var/log/messages
Jul 20 17:11:09 debian pppd[17058]: CHAP authentication succeeded
Jul 20 17:11:10 debian pppd[17058]: local IP address 211.145.37.188
Jul 20 17:11:10 debian pppd[17058]: remote IP address 220.192.0.22
Jul 20 17:11:10 debian pppd[17058]: primary DNS address 220.192.0.130
Jul 20 17:11:10 debian pppd[17058]: secondary DNS address 220.192.8.58
Jul 20 17:14:22 debian pppd[17058]: Terminating on signal 15
Jul 20 17:14:22 debian pppd[17058]: Connect time 3.2 minutes.
Jul 20 17:14:22 debian pppd[17058]: Sent 0 bytes, received 122 bytes.
Jul 20 17:14:22 debian pppd[17058]: Connection terminated.
Jul 20 17:14:22 debian pppd[17058]: Exit.
全部文件下载:aircard555.tgz
参考原地址: http://centerclick.org/aircard555/
如果使用pcmciautils,则直接将文件SW_555_SER.cis放到/lib/firmware/下,插入网卡以后,就会自动关联到设备文件/dev/ttyS0。
2007年06月22日 星期五
Debian 升级以后 Acrobat Reader无法打开
在某一次对Debian testing 进行了apt-get upgrade之后,偶然发现自己安装的Acrobat Reader不能正常启动了,报的错误是:
expr:语法错误
经过仔细查验acroread启动脚本,发现是升级Debian的过程中,libgtk2.0-0的版本从2.8.20-7升级到2.10.12-2。
对应的库文件由
/usr/lib/libgdk-x11-2.0.so.0.800.20
变成了
/usr/lib/libgtk-x11-2.0.so.0.1000.12
而acroread启动脚本检查该文件版本时的脚本对应为
get_gtk_file_ver()
{
if [ -f "$1" ]; then
if [ -h "$1" ]; then
ifile=`readlink $1`
if [ $? -eq 1 ]; then
return 1
fi
fi
mfile=`basename $ifile`
echo $mfile | grep -q "libgtk-x11-\([0-9]*\).0.so.0.\([0-9]*\).\([0-9]*\)" 2>/dev/null
if [ $? -ne 0 ]; then
return 1
fi
echo $mfile| sed 's/libgtk-x11-\([0-9]*\).0.so.0.\([0-9]\)00.\([0-9]*\)\|\(.*\)/\1\2\3/g'
return 0
fi
return 1
}
其中,sed行匹配版本号so.0.1000.12中的1000时只给了三位。
修改方法就显然了,将sed行改为
echo $mfile| sed 's/libgtk-x11-\([0-9]*\).0.so.0.\([0-9]\)*00.\([0-9]*\)\|\(.*\)/\1\2\3/g'
即可。
感谢icymoon花费时间调试!
2007年06月05日 星期二
fontconfig问题
新装系统如果执行fc-cache -fv,有时候会出现failed to write cache的情况。
这个问题是由于某些字体所在路径的创建时间要晚于系统当前时间。
逐个修改目录时间,或者干脆等几天就自然好了。
2007年05月01日 星期二
Mplayer打开文件出错
Debian testing
用Mplayer打开媒体文件,有的时候会报下面的错误:
ERROR: Could not open required DirectShow codec drvc.so.
解决方法:apt-get install libstdc++5
2007年04月23日 星期一
Beryl 快捷键
Alt + 鼠标滚轮 上/下使窗口 透明/不透明
Alt + Tab:在当前工作台中切换窗口
Ctrl + Alt + Tab:在所有工作台中切换窗口
Ctrl + Alt + 左/右方向键:立体地切换桌面
Ctrl + Shift + Alt + 左/右方向键:把活动窗口移到左/右工作台
Ctrl + Alt + 鼠标左键并拖曳:手动旋转立方体
Win + 鼠标滚轮 上/下:手动缩放大/小
Alt + 鼠标左键并拖曳:移动窗口
Win + m:屏幕反色
Win + n:当前窗口反色
Ctrl+Win + 鼠标左键并拖曳:将所选区域截图(图片保存在桌面)
鼠标左键点一下窗口标题栏,滑动中键,向上是卷起,向下是展开
Gnome 桌面上不显示已挂载的硬盘图标
使用Gnome桌面,并且在fstab中挂载了很多其他分区,烦人的是,每个挂载的分区都会在桌面上显示一个分区图标,很是烦人。
解决办法是:
1. 应用程序->系统工具->配置编辑器(gconf-editor)
2. 找到 /apps/nautilus/desktop/volumes_visible,去掉勾选即可。
2006年12月12日 星期二
Debian testing on R60e
新近购置了一台IBM(Lenovo) R60e 065877C。花了俺好多银子。心疼啊!
安装Debian Linux的过程更是说起来就是一把泪啊,好在有rmingming牺牲大量时间帮助,终于将其驯服。现在将一些注意的问题记录一下。
选择Debian也是经过很长时间学习才发现其好用之处的,尤其是依赖关系解决的太棒了。原来用过很多其他的发行版,最后发现还是debian适合像我这样的懒人。而且,我们楼里就有安装源,速度可以保证。按下不表,先说正题。
刻一张debian的网络安装盘,安装基本系统,R60e支持USB启动,也可以做成USB安装,具体参考:http://www.debian.org/releases/stable/i386/index.html.zh_CN。
安装基本系统没有问题。重启以后配置完安装源,运行
apt-get update
apt-get dist-upgrade
运行几次apt-get upgrade基本上就可以了。
更新内核:我们这里安装源最新内核是2.6.17-2。apt安装没有问题,但是最后生成的initrd.img不对,需要手动生成
mkinitrd -o /boot/initrd.img-2.6.17-2-686 /lib/modules/2.6.17-2-686/
否则,重启就无法用新内核进入系统。需要注意的是如果initrd-tools的版本不一样的话,也有可能导致生成的initrd.img不一样,会使机器无法启动。
安装图形界面,软件就不说了。我用的是gnome,还有其他一大堆软件。
主要是硬件设备驱动。
网卡:Broadcom NetXtreme BCM5751M Gigabit Ethernet
安装基本系统的时候设置网络,安装程序无法直接认出网卡,在选择的时候选Broadcom的tg3就可以,虽然安装程序自带的驱动可能觉得老了点,但是好像最新的驱动也是一样,没有任何变化。
显卡:集成Intel 945GM
安装xorg配置显卡的时候,使用驱动i810即可,可以直接驱动板载的945GM没有问题。
声卡:板载Intel HDA
安装完linux-sound-base和alsa-base应该就可以了。用gnome的音量控制就可以调出声音来应该。
不过最好安装esound,否则gnome事件的声音好像没法播放。
无线网卡:Intel PRO/Wireless 3945ABG
到http://ipw3945.sourceforge.net/下载驱动,按照说明一步一步来就可以。
首先下载内核代码和头文件,可以直接使用module-assistant这个程序。
我编译了一次内核,然后一切OK。
按照驱动安装说明,需要将内核的ieee80211模块进行替换,然后安装新模块ipw3945,并安装守护进程。
interfaces文件里面iface的写法就依赖于无线网的具体情况了。我的interfaces很简单。
# wireless interface used in my lab
iface eth1 inet dhcp
wireless-essid linksys
wireless-key off
wireless-ap 00:0C:41:9D:3C:A3
加在内核模块ipw3945可以写到/etc/modules里面,守护进程启动可以写到/etc/rc.local里面。
启用无限网络还是等机器以来以后ifup比较好,好像都写到启动脚本里面不怎么管用。
键盘Fn功能键,需要安装tpb。虽然配置tpb可以随X启动,但是由于设备文件nvram放在了,/dev/.static/dev/下面,每次重启系统以后.static的权限都变了。所以直接将设备文件建到了/目录下
mknod /nvram c 10 144
chmod 666 /nvram
然后,修改/etc/tpbrc。修改参数NVRAM就可以了。
当然,tpb默认定义的Fn功能键还差一些,需要进一步研究了,现在能用的有音量、亮度、数字键盘、键盘灯、截屏、挂起。
F*的功能还有几个没有。而且挂起事实上是利用gnome-power-manager实现,不过只是锁屏,休眠还不支持。
投影仪切换是直接在xorg.conf里面设置的
Section "Device"
Identifier "Generic Video Card"
Driver "i810"
BusID "PCI:0:2:0"
Option "MonitorLayout" "NONE,CRT+LFP"
EndSection
这样,是同时向LCD和投影仪显示。另外,虽然BIOS里面设置显示可以是Both,但是事实上,终端状态下,LCD和投影仪只有一个可以显示。
保存gnome的声音设置:
每次虽然调整了声音的设置,但是重启机器以后又会恢复初始状态。
需要安装alsa-utils,调整完以后运行alsactl store,将当前配置存到系统默认配置里,然后每次启动就可以了。
电源管理,直接安装acpi和acpid就可以了。
时间同步:
系统启动时需要从机器硬件时钟读取本地时间,关机的时候也会同步,但是系统默认的读取会报错
select() to /dev/rtc to wait for clock tick timed out
解决方法是,修改/etc/init.d/两个文件hwclock.sh和hwclockfirst.sh,修改其中的HWCLOCKPARS=--directisa就可以了。
2006年11月08日 星期三
tetex+CCT for Ubuntu edgy
装了ubuntu edgy, 写tex用Kile也很方便。平时都是写英文文档,这几天老板要我写份讲义,要求用CCT。所以只好安装CCT。
首先,要安装tetex。
apt-get install tex-common tetex-base tetex-bin tetex-extra
apt-get install cjk-latex dvipdfm-cjk dvipdfmx fontforge
然后,到 ftp://ftp.cc.ac.cn/pub/cct/Linux/下载
cct_0.6180.3a_i386.deb和cct-fonts_1.2.0_i386.deb,并安装
dpkg -i cct_0.6180.3a_i386.deb
dpkg -i cct-fonts_1.2.0_i386.deb
从ftp://ftp.cc.ac.cn/pub/cct/CJK/下载CJK-GBKfonts-0.3-15.i386.rpm
用alien转换为deb包并安装
alien --scripts CJK-GBKfonts-0.3-15.i386.rpm
dpkg -i cjk-gbkfonts_0.3-15_i386.deb
最后,我们需要一些字体, 将windows下的字体直接拷贝到/usr/share/fonts/truetype/下面,其他字体也是一样。
gbkfont-inst /usr/share/fonts/truetype/simsun.ttf song
gbkfont-inst /usr/share/fonts/truetype/simkai.ttf kai
gbkfont-inst /usr/share/fonts/truetype/simhei.ttf hei
gbkfont-inst /usr/share/fonts/truetype/simfang.ttf fang
gbkfont-inst /usr/share/fonts/truetype/simyou.ttf you
gbkfont-inst /usr/share/fonts/truetype/simli.ttf li
OK,可以了。
2006年10月12日 星期四
2006年06月03日 星期六
How to write a Makefile
How to write a Makefile
Introduction
Make is one of the original Unix tools for Software Engineering. By
S.I. Feldman of AT&T Bell Labs circa 1975. But there are public
domain versions (eg. GNU) and versions for other systems
(eg. Vax/VMS).
Related tools are the language compilers (cc, f77, lex, yacc, etc.)
and shell programming tools (eg. awk, sed, cp, rm, etc.). You need to
know how to use these.
Important adjuncts are lint (source code checking for obvious errors)
ctags (locate functions, etc. in source code) and mkdepend. These are
nice, and good programmers use them.
Important, and related tools, are the software revision systems SCCS (Source Code Control System) and RCS (Revision Control System -- the recommended choice)
The idea is to automate and optimize the construction of
programs/files -- ie. to leave enough foot prints so that others can
follow.
Makefile Naming
make is going to look for a file called Makefile, if not found then a
file called makefile. Use the first (so the name stands out in
listings).
You can get away without any Makefile (but shouldn't)! Make has
default rules it knows about.
Makefile Components
- Comments
Comments are any text beginning with the pound (#) sign. A
comment can start anywhere on a line and continue until the end of the
line. For example:
# $Id: slides,v 1.2 1992/02/14 21:00:58 reggers Exp $
- Macros
Make has a simple macro definition and substitution mechanism. Macros are defined in a Makefile as
= pairs. For example:
MACROS= -me
PSROFF= groff -Tps
DITROFF= groff -Tdvi
CFLAGS= -O -systype bsd43
There are lots of default macros -- you should honor the existing naming conventions. To find out what rules/macros make is using type:
% make -p
NOTE: That your environment variables are exported into the make as macros. They will override the defaults.
You can set macros on the make command line:
% make "CFLAGS= -O" "LDFLAGS=-s" printenv
cc -O printenv.c -s -o printenv
- Targets
You make a particular target (eg. make all), in none specified then the first target found:
paper.dvi: $(SRCS)
$(DITROFF) $(MACROS) $(SRCS) >paper.dvi
NOTE: The the line beginning with $(DITROFF) begins with TAB not spaces.
The target is made if any of the dependent files have changed. The dependent files in this case are represented by the $(SRCS) statement. - Continuation of Lines
Use a back slash (\). This is important for long macros and/or rules.
- Conventional Macros
There are lots of default macros (type "make -p" to print out the defaults). Most are pretty obvious from the rules in which they are used:
AR = ar
GFLAGS =
GET = get
ASFLAGS =
MAS = mas
AS = as
FC = f77
CFLAGS =
CC = cc
LDFLAGS =
LD = ld
LFLAGS =
LEX = lex
YFLAGS =
YACC = yacc
LOADLIBS =
MAKE = make
MAKEARGS = 'SHELL=/bin/sh'
SHELL = /bin/sh
MAKEFLAGS = b
- Special Macros
Before issuing any command in a target rule set there are certain special macros predefined.
- $@ is the name of the file to be made.
- $? is the names of the changed dependents.
So, for example, we could use a rule
printenv: printenv.c
$(CC) $(CFLAGS) $? $(LDFLAGS) -o $@
alternatively:
printenv: printenv.c
$(CC) $(CFLAGS) $@.c $(LDFLAGS) -o $@
There are two more special macros used in implicit rules. They are:
- $< the name of the related file that caused the action.
- $* the prefix shared by target and dependent files.
- $@ is the name of the file to be made.
- Makefile Target Rules
The general syntax of a Makefile Target Rule is
target [target...] : [dependent ....]
[command ...]
Items in brackets are optional, ellipsis means one or more.
Note the tab to preface each command is required.
The semantics is pretty simple. When you say "make target"
make finds the target rule that applies and, if any of the
dependents are newer than the target, make executes the com-
mands one at a time (after macro substitution). If any
dependents have to be made, that happens first (so you have
a recursion).
A make will terminate if any command returns a failure sta-
tus. That's why you see rules like:
clean:
-rm *.o *~ core paper
Make ignores the returned status on command lines that begin
with a dash. eg. who cares if there is no core file?
Make will echo the commands, after macro substition to show
you what's happening as it happens. Sometimes you might want
to turn that off. For example:
install:
@echo You must be root to install
- Example Target Rules
For example, to manage sources stored within RCS (sometimes
you'll need to "check out" a source file):
SRCS=x.c y.c z.c$(SRCS):
co $@
To manage sources stored within SCCS (sometimes you'll need
to "get" a source file):
$(SRCS):
sccs get $@
Alternativley, to manage sources stored within SCCS or RCS
let's generalize with a macro that we can set as required.
SRCS=x.c y.c z.c
# GET= sccs get
GET= co$(SRCS):
$(GET) $@
For example, to construct a library of object files
lib.a: x.o y.o z.o
ar rvu lib.a x.o y.o z.o
ranlib lib.a
Alternatively, to be a bit more fancy you could use:
OBJ=x.o y.o z.o
AR=arlib.a: $(OBJ)
$(AR) rvu $@ $(OBJ)
ranlib $@
Since AR is a default macro already assigned to "ar" you can
get away without defining it (but shouldn't).
If you get used to using macros you'll be able to make a few
rules that you can use over and over again.
For example, to construct a library in some other directory
INC=../misc
OTHERS=../misc/lib.a$(OTHERS):
cd $(INC); make lib.a
Beware:, the following will not work (but you'd think it
should)
INC=../misc
OTHERS=../misc/lib.a$(OTHERS):
cd $(INC)
make lib.a
Each command in the target rule is executed in a separate
shell. This makes for some interesting constructs and long
continuation lines.
To generate a tags file
SRCS=x.c y.c z.c
CTAGS=ctags -x >tagstags: $(SRCS)
${CTAGS} $(SRCS)
On large projects a tags file, that lists all functions and
their invocations is a handy tool.
To generate a listing of likely bugs in your problems
lint:
lint $(CFLAGS) $(SRCS)
Lint is a really good tool for finding those obvious
bugs that slip into programs -- eg. type classes, bad argu-
ment list, etc.
- Some Basic Make Rule
People have come to expect certain targets in Makefiles. You
should always browse first, but it's reasonable to expect
that the targets all (or just make), install, and clean will
be found.
- make all -- should compile everything so that you can do local testing before installing things.
- make install -- should install things in the right places. But watch out that things are installed in the right place for your system.
- make clean -- should clean things up. Get rid of the executables, any temporary files, object files, etc.
You may encounter other common targets, some have been
already mentioned (tags and lint).
- make all -- should compile everything so that you can do local testing before installing things.
- An Example Makefile for printenv
# make the printenv command
#
OWNER=bin
GROUP=bin
CTAGS= ctags -x >tags
CFLAGS= -O
LDFLAGS= -s
CC=cc
GET=co
SRCS=printenv.c
OBJS=printenv.o
SHAR=shar
MANDIR=/usr/man/manl/printenv.l
BINDIR=/usr/local/bin
DEPEND= makedepend $(CFLAGS)
all: printenv# To get things out of the revision control system
$(SRCS):
$(GET) $@
# To make an object from source
$(CC) $(CFLAGS) -c $*.c# To make an executable
printenv: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS)# To install things in the right place
install: printenv printenv.man
$(INSTALL) -c -o $(OWNER) -g $(GROUP) -m 755 printenv $(BINDIR)
$(INSTALL) -c -o $(OWNER) -g $(GROUP) -m 644 printenv.man $(MANDIR)# where are functions/procedures?
tags: $(SRCS)
$(CTAGS) $(SRCS)# what have I done wrong?
lint: $(SRCS)
lint $(CFLAGS) $(SRCS)# what are the source dependencies
depend: $(SRCS)
$(DEPEND) $(SRCS)# to make a shar distribution
shar: clean
$(SHAR) README Makefile printenv.man $(SRCS) >shar# clean out the dross
clean:
-rm printenv *~ *.o *.bak core tags shar# DO NOT DELETE THIS LINE -- make depend depends on it.
printenv.o: /usr/include/stdio.h
- Makefile Implicit Rules
Consider the rule we used for printenv
printenv: printenv.c
$(CC) $(CFLAGS) printenv.c $(LDFLAGS) -o printenv
We generalized a bit to get
printenv: printenv.c
$(CC) $(CFLAGS) $@.c $(LDFLAGS) -o $@
The command is one that ought to work in all cases where we
build an executable x out of the source code x.c This can be
stated as an implicit rule:
.c:
$(CC) $(CFLAGS) $@.c $(LDFLAGS) -o $@
This Implicit rule says how to make x out of x.c -- run cc
on x.c and call the output x. The rule is implicit because
no particular target is mentioned. It can be used in all
cases.
Another common implicit rule is for the construction of .o
(object) files out of .c (source files).
.o.c:
$(CC) $(CFLAGS) -c $<
alternatively
.o.c:
$(CC) $(CFLAGS) -c $*.c
- Make Dependencies
It's pretty common to have source code that uses include
files. For example:
% cat program.c#include
#include "defs.h"
#include "glob.h"
etc....
main(argc,argv)
etc...
The implicit rule only covers part of the source code depen-
dency (it only knows that program.o depends on program.c).
The usual method for handling this is to list the dependen-
cies separately;
etc...
$(CC) $(CFLAGS) -c $*.c
etc...
program.o: program.c defs.h glob.h
Usually an implicit rule and a separate list of dependencies
is all you need. And it ought to be easy enough to figure
out what the dependencies are.
However, there are a number of nice tools around that will
automatically generate dependency lists for you. For example
(trivial):
DEPEND= makedepend $(CFLAGS)
etc...
# what are the source dependenciesdepend: $(SRCS)
$(DEPEND) $(SRCS)etc....
# DO NOT DELETE THIS LINE -- ....printenv.o: /usr/include/stdio.h
These tools (mkdepend, mkmkf, etc.) are very common these
days and aren't too difficult to use or understand. They're
just shell scripts that run cpp (or cc -M, or etc.) to find
out what all the include dependencies are. They then just
tack the dependency list onto the end of the Makefile.
2006年06月02日 星期五
SuSE10.1的Xgl
按照http://www.novell.com/coolsolutions/feature/17174.html
的说明直接可以安装成功。
只是在安装完Xgl和compiz,并且做完设置以后还需要重启gnome才能打开gnome-session-properties继续进行设置。
最后的效果截图:

2006年05月26日 星期五
硬盘安装SUSE10.1
新版SUSE终于发布了,历经了几天的下载,中间还有两张iso的md5sum出错,终于把五张SUSE-Linux-10.1-GM-i386-CD*.iso下载了下来。本来琢磨这刻出盘来安装的,无奈手头白盘没有了,于是就有了这篇从硬盘安装的笔记。
看了网上一些关于从硬盘安装Linux的帖子以后,开始了自己的实践。
我的机器现装了Windows 2003 Server, 硬盘80G,分成了c,d,e三个分区,预留15G给linux.
1。从以下地址
http://grub4dos.sourceforge.net/
下载grub for dos。
解压后将文件grldr拷贝到C盘根目录,并修改C盘根目录下面的boot.ini文件,添加grub启动项,具体形式如下:
[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows Server 2003, Enterprise" /noexecute=optout /fastdetect
C:\grldr="GRUB"
2. 我的五张ISO都下载到了E:\suse目录下,将SUSE-Linux-10.1-GM-i386-CD1.iso解压到D:\cd1下面,
(我这里很奇怪,原本解压在E盘下面的,可是grub启动之后死活找不到E盘,所以放到了D盘下面)
将D:\cd1\boot\i386\loader\下面的linux和initrd两个文件拷贝到D盘根目录下,(这里也可以放到E盘根目录下)。
OK,下面就可以重启机器了。
3。重启机器,选择Grub引导。进入grub命令提示符之后,需要执行以下命令
grub> find /linux
返回 (hd0,4)
grub> kernel (hd0,4)/linux root=/dev/ram
(返回忽略)
grub> initrd (hd0,4)/initrd
(返回忽略)
grub> boot
就可以看到启动了机器
4。此时启动的系统只需要做几项设置,包括语言、键盘布局、还有就是安装源了
我的安装源是hda5,然后设置路径为cd1.
这是系统就自动读取安装信息进入Suse的安装程序了。
5。其他忽略不表,正常选择和设定,安装第一张光盘完成后会自动重启计算机。
在重启以后,由于找不到第二张光盘的解压路径,会报错,一般错误会是类似这样的信息:
hd:///cd1?device=/dev/hda5???filetype=auto(差不多吧,如果记得不差的话)
因为我们只解压了一张ISO,如果把所有ISO都依次解压为cd1,cd2,cd3,cd4,cd5五个文件夹的话,这个问题就不会有了,关键问题就是这样太浪费空间了。
这时,需要Ctrl+Alt+F2(F3-F6也可)切换到控制台方式下面,这时是有root shell的
我们需要手动挂载没有解压的几个ISO文件
cd /media
mkdir win-e
mount /dev/hda6 /media/win-e
mkdir cd2
mkdir cd3
mkdir cd4
mkdir cd5
mount -o loop /media/win-e/suse/SUSE-Linux-10.1-GM-i386-CD2.iso /media/cd2
mount -o loop /media/win-e/suse/SUSE-Linux-10.1-GM-i386-CD3.iso /media/cd3
mount -o loop /media/win-e/suse/SUSE-Linux-10.1-GM-i386-CD4.iso /media/cd4
mount -o loop /media/win-e/suse/SUSE-Linux-10.1-GM-i386-CD5.iso /media/cd5
OK,按键Alt+F7回到图形界面,报错窗口中选中“显示细节”,将URL(依次)修改为
dir:///media/cd2
即可继续安装系统了。
2006年04月10日 星期一
Suse10安装 QtiPlot - Data analysis and scientific plotting
Linux下面的Origin
安装源文件都位于/software下
1.安装QwtPlot3D
下载地址:http://qwtplot3d.sourceforge.net/web/navigation/download_frame.html
解压qwtplot3d-0.2.6.tgz
mkdir /usr/include/qwtplot3d
将/software/qwtplot3d/include目录下所有文件拷贝至/usr/include/qwtplot3d
在/software/qwtplot3d/运行
/usr/lib/qt3/bin/qmake(我的Suse把qt3装在此目录)
这时make时会报错误,说-lXmu找不到库文件,Suse10下libXmu装的路径是/usr/X11R6/lib/
修改Makefile,将
LIBS = $(SUBLIBS) -L/usr/lib/ -L$(QTDIR)/lib/ -L/usr/lib/ -lz -lqt-mt -lGLU -lGL -lXmu -lpthread
改为
LIBS = $(SUBLIBS) -L/usr/lib/ -L$(QTDIR)/lib/ -L/usr/lib/ -L/usr/X11R6/lib/ -lz -lqt-mt -lGLU -lGL -lXmu -lpthread
然后make就可以了
把/software/qwtplot3d/lib/下所有文件拷贝至/usr/lib/下
2. 安装GSL库
下载地址:http://www.gnu.org/software/gsl/
beat@huang:/software> tar -zxvf gsl-1.7.tar.gz
beat@huang:/software> cd gsl-1.7/
beat@huang:/software/gsl-1.7> ./configure --prefix=/usr/
beat@huang:/software/gsl-1.7> make
beat@huang:/software/gsl-1.7> su
huang:/software/gsl-1.7 # make install
3. 安装qtiplot
下载地址:http://soft.proindependent.com/qtiplot.html
beat@huang:/software> tar -xf qtiplot-0.8.2.tar
beat@huang:/software> cd qtiplot-0.8.2/
beat@huang:/software/qtiplot-0.8.2> export PATH=$PATH:/usr/lib/qt3/bin/
beat@huang:/software/qtiplot-0.8.2> qmake
beat@huang:/software/qtiplot-0.8.2> make
beat@huang:/software/qtiplot-0.8.2> su
huang:/software/qtiplot-0.8.2 # make install
好啦,装完拉
2006年04月09日 星期日
Gaim使用Google Talk
系统Suse 10
Gaim 版本 1.5.0-3
启动Gaim,选择帐户,添加;
协议选Jabber,用户名是gmail帐号(不含@gmail.com),服务器写:gmail.com;
密码是gmail邮箱密码;别名可任意取。
点下面的”显示全部选项“,只勾选“若可用则使用TLS”,端口:5222,连接服务器:talk.google.com。
然后确定,就可以登录使用Google Talk了。
2006年04月04日 星期二
Richard Stallman ”未来的自由软件”
会议: 意大利都灵GPLv3会议
时间: 2006-03-18 9:30到13:30
演讲人: Richard Stallman
主题: 未来的自由软件
演讲文稿
Richard Stallman:
Before I get into the main subject, which is the plans for version three of the GPL, I want to mention a very important fundamental issue.
[1h 27m 06s]
There is a term that some people use, which causes terrible confusion and should never be used, and that is the term "intellectual property". Now, I heard someone mention that term. I don't think he was explaining why that term should not be used.
It is devastatingly harmful to use the term "intellectual property" because that term implies the existence of something which does not exist.
Copyright law exists. Patent law exists. They have almost nothing in common in terms of the requirements that they put on the public. Trademark law also exists. It has nothing in common with copyright law or patent law about what it requires of the public. So, the idea that there is some general thing which these are instances of already gets people so confused that they cannot understand these issues. There is no such thing. These are three separate unrelated issues, and any attempt to generalise about them guarantees confusion. Everyone who uses the term "intellectual property" is either confused himself or trying to confuse you.
[applause]
[1h 29m 12s]
I came to this conclusion a few years ago and since then I have decided that I will never use that term. No exceptions. I will talk about why the term is confusing, because that's a useful thing to do, but I will never use that term. I never use it. I hope you will join me in making this firm policy of never using it. And if someone else says something about "intellectual property", I will not respond directly to what he said without first explaining the confusion buried in it, because you see, the confusion buried in a statement is usually more harmful than whatever may be false that he actually tried to say.
The false premises, the false presuppositions are the most important problem. So, if someone makes a statement about intellectual property and some part of it is the specific point, which I might disagree with, the first thing I will say is why it's a mistake to talk about intellectual property at all, and then I will try to translate what he said into clearer terms, and then I might say if I agree with it or not. But that's secondary, and explaining to people the confusion in the term intellectual property itself is the most important thing to do.
There is a tendency to, we all have it, to follow other people in their choice of terminology. If someone says an outrageous thing and he uses the term intellectual property, you will feel drawn into responding in the same terms. So, learn to resist that temptation.
[1h 31m 20s]
The most important mistake, the most important falsehood in that statement is its use of the term "intellectual property" in the first place. And the most important thing about it to respond to, if you could only choose one thing, is that one. And you can say: "and since your whole picture of the situation is totally confused, clearly the specifics of what you said need to be rethought".
That's all you need to do to deal with the specific thing he said.
And, by the way, when the term "intellectual property" is used in the name of a law or a committee, that is an example of the confusion. It's almost a certainty that any law named "intellectual property" is a harmful, an unjust law. Of course, you have to check the details to be sure of that, but you can be almost certain just from hearing the name. And the reason is that you can tell from the name that unjust premises and confusions went into the design of the law so what could you expect except harmfulness.
[1h 33m 00s]
So, at this point, I should go to the intended topic, which is version three of the GPL.
I designed GPL version one in 1989, and GPL version two in 1991. I thought of making a version three something like five or six years ago. We didn't intend to wait fifteen years. It was due to the fact that I was busy, and there were some things that were hard to figure out.
The idea that there would be changes in the GPL was planned from the beginning. That is, version one already included a plan for transition to future versions. We suggested that people release their programs under "version one or any later version of the GPL", and the idea was that when version two came out, it would automatically be usable for all those programs and in the time since version two, we've been suggesting that people release their software under "version two or any later version" and I believe most GPL covered programs do say that, with the result that when GPL version three comes out, a lot of software will be usable under GPL version three.
The older versions of the GPL also promise that future versions would be "similar in spirit". In other words, the changes will not be radical. Any radical change would be false to the spirit and would be wrong.
[1h 35m 17s]
The changes that we've proposed in version three are all in small sub-issues. Some of them are very important, but in the overall framework, they're small changes. And the overall effect of GPL version three will be basically the same as version two, protecting the same four freedoms, but doing it somewhat better, dealing with some problems which we've encountered and adapting better to various different laws around the world.
One thing that we've done is that we've restructured some of the concepts, for instance, we make it clear that many other activities that have the effect of providing copies to other people are treated the same as distribution. Anything that's covered by copyright law which has the effect that it enables other people to get copies is effectively equivalent to distribution, and this insulates GPL version three from certain differences between laws in various countries about just what constitutes distribution. So it has the effect of making the GPL work more the same in all countries, despite precisely how they have formulated their copyright laws.
There are many changes in GPL version three which do something like that, they actually just make it more uniform and more reliably doing the same thing we expected it already did.
[1h 37m 20s]
But there are some places where we actually have changed the policies in small ways. One of these concerns software patents. GPL version two is based on an implicit grant of a patent licence. The idea is that if somebody says "here is a thing and you can use it", implicitly he's promising he's not going to sue you for patent infringement if you go ahead and do what he said; however, since in the past eight years or so some other free software licences have included explicit statements of patent licenses, patent licence grants by people distributing the software, and so we decided to do the same thing, and we've included an explicit statement that the distributors of the software all promise not to sue anybody who is using any version of that software for patent infringement based on the versions that they distributed. Basically, whatever their versions do, they're promising not to sue you for.
However, there's a subtlety that came up in this. What if somebody doesn't have a patent but he has got a licence for that patent, and he distributes the code to you. Well, does that licence he got include your exercise of the four freedoms? Including your freedom to redistribute copies yourself, with changes? Maybe not, but if it doesn't, it creates a dangerous and unfair situation. Unfair to you because he is distributing the software, or distributing his version of the software, and he is not going to get sued for patent infringement because he got a licence. He distributes it to you under the GPL and the GPL says you are free to redistribute it too, but if you do that you might get sued because his patent license might not cover you.
[1h 40m 04s]
Well, this is unfair, this is something that's not supposed to happen. He received this program under the GPL and the GPL says when he distributes a version of it, he must really give you the freedom to do the same. If he can count on safely doing it, and he knows you will get sued if you do it, by a third party, he's cheating. So, GPL version three, along with the explicit patent licence grant, says that if he is knowingly relying on a patent licence for distributing his version, he must take some effective step to protect you as well if you distribute.
Now, the reason it talks about "knowingly relying" is that there are companies that have signed blanket cross licences with other companies, so the company distributing the program, might have some blanket cross licence with some company, and that blanket cross licence might cover a thousand patents, and they don't even know what those thousand patents say. So, if they don't even know that they have a patent licence, they're not required to pay attention, but if they know about a specific patent that would cover this program, that means they are knowingly relying on a patent licence and that means they have to keep you safe as well. This is a very controversial decision. It may seem like a subtle point, it covers a peculiar scenario, but it's not an impossible scenario. It could be a very important scenario. In this scenario, this point is essential to ensure that the GPL really does what it intends to do, which is, make sure that you do get the freedom to redistribute the software that you got. And this is typical of the ways that we are changing GPL version three. They apply to complicated scenarios but those scenarios may happen frequently, and in those scenarios we are trying to make sure that you really get the four fundamental freedoms which that free software.
Did someone earlier already describe the four freedoms?
Then I better do so.
[1h 42m 43s]
Freedom zero is the freedom to run the program as you wish for any purpose.
Freedom one is the freedom to study the source code and change it to do what you wish.
Freedom two is the freedom to help your neighbour, that's the freedom to make copies and distribute them to others when you wish.
Freedom three is the freedom to help your community, that's the freedom to publish or distribute modified versions when you wish.
So here we're talking about what is necessary to ensure that freedom two really exist for you in a certain special scenario, freedom two being the freedom to redistribute copies and also freedom three, it applies to that too.
[1h 43m 35s]
Another area where we have made changes concerns Digital Restrictions Management. Now, freedom zero says you are free to run the program as you wish for any purpose. We are not limiting freedom zero. If someone wants to run a program to encrypt something, that's fine. If someone wants to run a program to decrypt something, that's fine. If somebody wants to run a program to produce an encrypted medium that's difficult to access, that's fine. If somebody has some other GPL covered program to access that media and he wants to run it to access the encrypted data, that's fine too. And distributing software that could be used for those purposes is also entirely permitted, and will be permitted by GPL version 3.
[1h 44m 58s]
However, freedom zero does not include imposing your purposes on someone else who is going to run the program, because his freedom zero is the freedom to run the program for any purpose of his. So, there is no such thing as the freedom to use any software to impose your purpose on someone else. In fact, that should be illegal. I'm serious. And that's what DRM is.
When somebody distributes a player, that has DRM in it, what he's doing is trying to restrict your running of your computer for his purposes, which is directly in conflict with the four freedoms that you should have.
And that's what GPLv3 is in certain ways trying to stop and it does this simply by assuring you all four of the freedoms when you use the software. You see, because DRM - Digital Restrictions Management - is a plan to restrict the public, anyone distributing a version of a GPL-covered program as a player for DRM media always does something to stop the public from modifying the player, because his purpose in distributing a DRM player is to restrict you, he has to make sure you can't escape from his restrictions, from his power. That means he is always going to try to deny you freedom one. Freedom one is the freedom to study the source code of the program and change it to do what you want. What you want, might be, to escape from his restrictions, and if you have freedom one, you can escape from his restrictions. So his goal is somehow or other, for practical purposes, to deny you freedom number one.
[1h 47m 26s]
Now, what he might do is, use non-free software, and then completely deny you freedom number one. In fact, that's what they usually do. We can't change that with the GPL because they're not including any GPL-covered code. They don't have to pay attention to the GPL. There should just be a law against it. It should be illegal. DRM should be illegal, but we can't change laws by modifying the GPL.
However, there are those that want to use GPL-covered software for this purpose, and they want to do so by turning freedom number one into a sham, a facade. So they plan to do something like, make a modified version of the GPL-covered program, which contains code to restrict you, and distribute that to you and somehow arrange that you can't really modify it, or if you modify it it won't run, or if you modify it and operate it, it won't operate on the same data.
[1h 48m 42s]
They do this in various ways. This is known as Tivo-isation because this is what the Tivo does. The Tivo includes some GPL-covered software. It includes a GNU+Linux system, a small one, but it does, and you can get the source code for that, as required by the GPL because many parts of GNU+Linux are under the GPL, and once you get the source code, you can modify it, and there are ways to install the modified software in your Tivo and if you do that, it won't run, period. Because, it does a check sum of the software and it verifies that it's a version from them and if it's your version, it won't run at all. So this is what we are forbidding, with the text we have written for GPL version three. It says that the source code they must give you includes whatever signature keys, or codes that are necessary to make your modified version run.
In other words, it ensures that freedom number one is real. That you really can modify the source code, install it, and then it will run and not only that, we say, they must give you enough to make the modified version operate on the same range of data. Because, you see, Microsoft's plan, which they call Palladium, and then they change the name - they change these names frequently so as to evade criticism, to make criticism difficult, to make any kind of comment on their plans difficult. You talk about their plan and they say "Oh, we've dropped that, we have a different plan now". And probably it is different in some details, but the point is that they generate encryption and decryption keys using a check sum of the program which means that a different program can't possibly access the same data. Although, that's just the base level, and then on top of that they implement other facilities where the program simply has to be signed by the authorised signer in order to be able to access the data.
[1h 51m 29s]
Well, GPL version three says that if they distribute a GPL-covered program in this way, they must provide you with the key necessary so that you can sign your version and make it access the same data. Otherwise, they would say "Yes, you can run your modified version, but it will have a different check sum, so your version will only operate on data files made for your version, just as our version only operates on data made for our version". And what that means is that all the available files will only work with their version and your changed version will not be able to access them. That's exactly, in fact, how Treacherous Computing is designed to work. The plan is that they will publish files that are encrypted and it will be impossible to access those files with any other program, so GPL version three is designed to ensure that you really, effectively, get the freedom to take the program you were given, modify it, and run the modified version to do a different thing on the same data on the same machine.
But, there's one other way that we're trying to thwart DRM. You see, one thing they do is, some countries, including, I'm sad to say, this one, have adopted unjust laws that support DRM. The exact opposite of what they ought to do, which is prohibit DRM, and what they say is: when media have been encoded for DRM, then writing another program to access that media is illegal, and the way they do this is they say that DRM constitutes an effective, they call it "protection" I call it "restriction", measure. So, what we say is, by releasing a program under GPL version three, you agree that it is not an effective restriction measure. In other words, you authorise others to develop on their own software to read the output of your program.
This also is a matter of recognising and respecting their freedom to develop software and use their computers. And this, what I've described so far, is all that GPL version three says about DRM.
[1h 54m 36s]
Another area in which we've made large changes has to do with compatibility with a wide range of other free software licences.
We've always understood GPL version two, and version one, as being compatible with some other free software licences. Namely, those that don't require anything except what the GPL requires. So, for instance, there is the X11 licence, all it requires is that you keep the licence there. This doesn't actually demand anything that conflicts with the GPL, so we've always interpreted it as being compatible with the GPL, and what it means to say that two free software licences are compatible is that you can take code from a program under licence A and code from a program under licence B and put them together in one program and you have not violated either licence.
If both licences permit the combining of the code, then you can combine the code, and that's what it means to say the licences are compatible. Now, it's very useful to be able to combine the code, so compatibility of the licences is a convenient thing. Now, it's impossible for all free software licences to be compatible. You see, the GPL makes certain requirements and we are not willing to have them taken off, and so another licence, such as GPL version one, that doesn't have those requirements, cannot be compatible with GPL version two or three. That's impossible.
A licence like the Mozilla Public License has its own specific requirements, but it requires things the GPL doesn't require. It can't be compatible, I believe. So we can't be compatible with all of them, but we went through other free software licences and we identified certain kinds of requirements that are pretty harmless and we wouldn't mind if people could attach those kinds of requirements to GPL-covered programs, and we made an explicit list of those kinds of requirements. Section seven of the draft of GPL version three says you can put your own terms and conditions on code that you add to the GPL covered program, and your terms and conditions can include these kinds of requirements. You can also give additional permission. Any kind of additional permission you like. So your terms on your code can be more permissive than the GPL itself. And section seven makes it completely explicit that this is compatible with the GPL.
[1h 58m 22s]
Now, these, the added kinds of requirements that you can make, include different requirements as regards credit and notices and how to identify changes on your code. That's harmless, that only really is relevant when people change your code, and when they do that they will see your terms at the beginning of your code and they will know what to do. And it can include a requirement that they not use certain of your trademarks in ways that trademark law forbids. And this would just be a way of reinforcing trademark law using the copyright on your code. And that's harmless because you could actually do that with trademark law in the first place. So this doesn't actually restrict people in any way that they wouldn't be restricted otherwise.
[1h 59m 28s]
You can put on requirements that -- and this is a non-trivial kind of requirement that we've decided to let people put on -- requirements that if people run your code, on a publicly accessible server, then it must have a command that the user can use to download the source code of the version that is running. Which means that if someone makes changes and puts the changes in his version, on his server, he has to make his source code changes available to the users who talk to his server.
This requirement is known as the Affero clause because it's used in the Affero GPL. The Affero GPL is like GNU GPL version two except it has this requirement as well.
We were thinking of including some kind of requirement like that in GNU GPL version three. We didn't want to make it apply to everything automatically. That would be a drastic change, so we would have to make it something that people could activate explicitly for their programs, and then I realised people could activate it explicitly for their programs by putting the Affero GPL on their programs and as long as the GNU GPL says it's compatible with that, that's a way you could activate that requirement for your code and it means we don't have to put any specific thing about that in the GNU GPL, we only have to make the GNU GPL compatible with it and we did.
[2h 01m 33s]
There's another kind of requirement that we've decided to permit, and this is patent retaliation clauses. Now, the reason is that there are several other free software licences that have patent retaliation clauses.
Patent retaliation means, if you sue somebody for patent infringement, then you lose the right to use this code.
Of course there are many ways to do that because every patent retaliation clause puts on some specifics, if you sue him or him for patent infringement in certain circumstances, then you lose the right to use this code, and the question is, what are those circumstances, what are the conditions under which the retaliation operates.
Now, we saw that there are some very broad and nasty patent retaliation clauses. Some of them say, "if you sue me for patent retaliation, for any reason about anything, you lose the right to use this code". Now that's bad because it means, suppose I sue you for patent infringement and you have a patent so you counter sue me, and then my free software licence retaliates against you and you lose the right to use that code, now that's not fair because in that case you are defending yourself, you're not the aggressor, so we decided to accept only patent retaliation clauses that are limited enough that they do not retaliate against defense, that they only retaliate against aggression, so there are two kinds of clauses that we identified that do this. One is, if the clause itself, makes a distinction between defense and aggression, so it says, if you sue somebody for patent infringement and it's aggression, then you lose the right to use this code, but if you are suing in retaliation for aggression, then what you are doing is defensive and then we do not retaliate against you.
This is one kind of patent retaliation clause that we accept.
[2h 04m 21s]
The other kind is, if you sue, alleging that some free software, relating to this code is patent infringement, then you lose the right to use this code. In the broad space of possible kinds of patent retaliation clauses, we picked two kinds, each of which is limited enough that it will not retaliate against people for practicing defense with patents. It will only retaliate against aggressors. And we've said these two kinds of clauses are OK to add to your code in a GNU GPL covered program. This is a conceptually complicated thing. There's no way to make it any simpler, I hope, at least, that I've explained it clearly.
The GPL itself does contain one very limited kind of patent retaliation, but it's a different kind. It says if make changes in a GPL-covered program and then somebody else makes similar changes and you sue him for patent infringement then you lose the right to continue making changes and copying the program to your own machines.
This is a very limited situation and it's meant to protect against one particular kind of abuse on the part of server operators where they make an improvement, which they're free to do, and run it on their servers and they don't release their source code and if the code does not have the Affero clause on it then they don't have to release the source code, and then you decide that you are going to implement a similar improvement and then they sue you for patent infringement.
So, once again, we're making a change that keeps people honest and makes sure that the four standard freedoms that the four standard freedoms that the GPL has always tried to ensure, really apply in all cases.
This is pretty much it, but there is also one interesting change in the section that deals with modified versions. There has always been a requirement that if you get a program that prints some kind of notice about the licence when it starts up, you can't take that out. We've generalised that so that it applies to various kinds of user interfaces in various ways.
So, for instance, if the program is graphical and it has an "about" box, the about box has to say "this is free software under the GPL". And if it starts up interactively and asks for commands, then it has to print the notice at the beginning, and the requirements are a little bit different depending on how obtrusive this would be. For example, the about box is simply a menu item sitting in a menu, well that doesn't bother anybody, so we just say that always has to be there.
On the other hand, printing a notice at start up can be annoying, there are certain programs which shouldn't print notices at start up. So what we say is that if the program that you got doesn't print a notice and you change it, then your program doesn't have to print a notice either. You know, if you change Bash, well Bash isn't supposed to print a notice when it starts up and we don't require you make it print a notice, but if you gave it a GUI, with menus, you would have to put in an about box because the about box doesn't do any harm.
[2h 10m 02s]
I've covered all the issues I can think of that are worth discussing, and I am willing to ask for questions however you can discuss a question with me but if you think you see a problem, you should go to the site gplv3.fsf.org and report this problem and get it considered through our discussion committees and they'll either publish an answer eventually, or they will pass the issue on to me and I'll think about whether a change is needed.
So, I'm ready for questions.
[2h 10m 55s]
[applause]
Q1: I would like to ask, what is the position of Stallman, and to clarify a bit about the different position of the Linux community about Digital Rights Management.
Stallman: I can't speak for them, and I don't want to try. All I can point out is that Linux is one of thousands of programs in the GNU+Linux operating system. These programs already have various different licences. If some of those programs continue to be distributed under GPL version two while others move to GPL version three or to "GPL version three or later", that won't be any disaster. The developers of Linux are the ones who will decide which licence to use on their program, but I'm confident that most of the GNU+Linux system will be under the GPL version three, regardless of what the Linux developers decide about their program.
I hope that they will move to GPL version three because I want to see Linux resisting Tivo-isation. Linux, after all, is one of the programs that has already been Tivo-ised.
[applause]
Q2: (Question asked in Italian, something about linking and dynamic languages)
Stallman: Actually, there are changes making it clearer that it doesn't matter which kind of linking is being used. If there are two modules that are designed to be run linked together and it's clear from the design from one or the other that they are meant to be linked together then we say they are treated as one program and so I hope that will make it a little bit clearer although that's not really a change, it's a clarification. That's what we believe GPL version two means already.
Q3a: I have two different questions. The first is what happens if anyone released code under GPL version two maybe ten years ago and now isn't happy with version three and says you're changing the spirit, when I said I would release it under version two and subsequent version, I didn't think of these. Do you imagine he would be bound to version three, or...
Stallman: Yes. Because we're not changing the spirit. These are small changes.
Q3a2: OK, so basically, you're the one who judges...
Stallman: Well, maybe a court might, but I can't believe that anyone not strongly prejudiced would conclude that this is a change in the spirit. A change in the spirit certainly permits change in the details of the requirements and anyone who released it under version two or later should have seen the changes that were made from version one, which were not as big but they were the same kinds of things. So yeh, if he released it under GPL "two or later" you'll be able to use it now under version three.
Q3b1: OK, the second question is that, as you know, I'm involved in these United Nation processes on the Internet governance, so I'm interested to know, do you think the fight against Digital Rights Managements and Trusted Comp[interrupted]
Stallman: Digital Restrictions Management, and Treacherous Computing. Don't use the enemy's propaganda terms, every time you use those terms you are supporting the enemy.
[applause]
Q3b2: OK, so the correct term is Treacherous Computing right? So on the fight against these new mechanisms, do you think it can only be won by writing free software, releasing free software?
Stallman: I don't know.
Q3b3: Do you imagine that there should be need for intervention or lobbying at the legal level?
Stallman: I think Treacherous Computing should be illegal. But I don't know how we're going to convince governments to actually do that because governments mostly are not very democratic anymore. They mostly are the pro-consuls of the mega corporations, their job is to keep us in line under the rule of the empire. That's why they run for office, they get into office, they do what the emperor -- the emperor being the mega corporations -- tells them to do, and their job is explaining to us why they can't do what we want them to do. It's very very sad and once in a while somebody has enough courage to refuse to obey, somebody like [sounds like Hugo Chavez].
Q3b4: So do you think it's not even worth trying?
Stallman: Oh, it's worth trying. It's just going to be hard, the point is you have to keep putting the pressure on these politicians. In France, there is a battle going on and we still might win it about the legalisation of peer-to-peer copying on the Internet. This shows that when enough people get energised, the empire can lose a battle.
It's very important.
[applause]
[2h 19m 53s]
Stallman: Another thing that people should do is refuse to buy anything that's based on DRM. Don't buy corrupt disks, that is the fake CDs that have music set up so that you're blocked from copying it. Don't buy DVDs unless you have DeCSS and you can copy it.
If you can't copy it - don't buy it!
[applause]
[2h 20m 23s]
Q4: (Question in Italian, mentions Eben Moglen)
Stallman: Well, first, I'm the one who decides what goes into GPL version three, and, of course, whenever I think of language I'm usually working with Eben Moglen since he's a lawyer and he's the only one that can tell me if the language will really do what I hope it will do. Meanwhile, a lot of other people are involved. For instance, you can go to the gplv3.fsf.org site and study it and if you think you see something that's not good or whatever kind of problem you might think there is, you can report it and your comment will go to a discussion committee and, there are four discussion committees, it will go to one of those committees which will then group your comment with other comments that raise that same issue and then they will study each issue and post the issue and their response to it and your comment will be connected to the issue which they grouped it into so it will be connected to the response as well.
And thus, there are probably hundreds of people participating in checking the draft and trying to make sure it does the right thing.
Q5: In the end of the process of deciding what modifications of the licence will be done there's one single person, that is you. Can you explain why this decision and you have not chosen to make some group?
Stallman: I don't know other people who can do this.
I hope that the process that's going on now will help develop people who can be part of some group activity but at the moment, I don't know anyone that I could delegate this to. Obviously I can't always forever be the person doing this, barring unforeseen advances in medical technology or AI and nanotechnology, which I certainly hope will come soon but they're not likely, but at this point, I think this is the right thing to do.
Q5.2: Maybe it will change in the future.
Stallman: I hope. We're going to have to replace me somehow, sooner or later.
[applause]
[2h 24m 30s]
Q6: You told us about what GPLv3 will be, but what about the issues that are included, the suggestions that you refused. Can you give us some samples?
Stallman: Well, when I decided that we had to do something to resist Digital Restrictions Management, the obvious way to do this would be restrictions on what kinds of jobs the program can be made to do, but I decided that that would be the wrong way to do it and so I thought hard and I came up with a way to achieve the job by directly protecting the freedom of each user without any restrictions about what technical job a version of the program can do.
Another example of what we decided not to do was putting the Affero clause into the GNU GPL in some way.
Another example of something we decided not to do, we decided not to put in very much in the way of patent retaliation clause and the reason is we have doubts about how effective those clauses really can be. We have doubts about whether our community actually has enough power that the threat of our retaliation would scare anyone.
So, these are some examples of changes we decided not to do. Some for reasons of principle and some for practical reasons.
So, thank you for your attention, and happy hacking.
[applause]
2006年04月01日 星期六
pdflatex使用中文字体
首先,还是使用gbkfonts程序自动生成所有的字体文件和map。
将生成的所有文件按目录结构放到系统目录下面。
将cjk.map拷贝到texmf/fonts/map/
修改texmf/web2c/updmap.cfg
最后面加上Map cjk.map
运行mktexlsr,运行updmap即可。
2006年03月25日 星期六
SuSE10安装Mplayer
近几天来访问此篇文章的多数是要解决Mplayer编译时gcc4版本的问题,其实只需要下载CVS版本安装就不存在这个问题了。打patch的只限于MPlayer v1.0pre7的版本。大家大可不必如此费神。
0. 首先需要安装两个开发包:gtk-1.2.10-888和glib-devel-1.2.10-595
1. 预备工作
到http://www.mplayerhq.hu/design7/dload.html下载以下安装文件:
主程序:MPlayer v1.0pre7try2 源码
解码器:all-20050412.tar.bz2
字体:font-arial-cp1250.tar.bz2,font-arial-iso-8859-1.tar.bz2,font-arial-iso-8859-2.tar.bz2,font-arial-iso-8859-7.tar.bz2
皮肤:PowerPlayer-1.1.tar.bz2(以此为例)
到http://www.chinalinuxpub.com/bbs/attachment.php?attachmentid=4380下载mplayer-1.0_pre7-gcc4-fix.patch.zip
因为suse10上的gcc版本太高,所以必须要给mplayer打补丁才能安装。
2. 安装解码器
huang:/software/mplayer # tar xvf all-20050412.tar.bz2
huang:/software/mplayer # mv all-20050412/ /usr/local/lib/codecs
huang:/software/mplayer # ln -s /usr/local/lib/codecs /usr/lib/win32
3. 安装主程序
huang:/software/mplayer # tar xvf MPlayer-1.0pre7try2
打补丁,只有 gcc-4.0 的时候才需要打补丁。
huang:/software/mplayer # unzip mplayer-1.0_pre7-gcc4-fix.patch.zip
huang:/software/mplayer # cd MPlayer-1.0pre7try2/
huang:/software/mplayer/MPlayer-1.0pre7try2 # patch -p1 < ../mplayer-1.0_pre7-gcc4-fix.patch
为了是mplayer的GUI支持UTF8中文,需要改变一个文件的编码
huang:/software/mplayer/MPlayer-1.0pre7try2 # cd help/
huang:/software/mplayer/MPlayer-1.0pre7try2/help # mv help_mp-zh_CN.h help_mp-zh_CN.h.bak
huang:/software/mplayer/MPlayer-1.0pre7try2/help # iconv -f GB2312 -t UTF-8 help_mp-zh_CN.h.bak -o help_mp-zh_CN.h
配置
huang:/software/mplayer/MPlayer-1.0pre7try2 # ./configure --enable-gui --language=zh_CN --prefix=/usr/local/mplayer/
huang:/software/mplayer/MPlayer-1.0pre7try2 # make
huang:/software/mplayer/MPlayer-1.0pre7try2 # make install
4. 安装字体
huang:/software/mplayer/MPlayer-1.0pre7try2 # cd ..
huang:/software/mplayer # tar xvf font-arial-cp1250.tar.bz2
huang:/software/mplayer # tar xvf font-arial-iso-8859-1.tar.bz2
huang:/software/mplayer # tar xvf font-arial-iso-8859-2.tar.bz2
huang:/software/mplayer # tar xvf font-arial-iso-8859-7.tar.bz2
huang:/software/mplayer # mv font-arial-cp1250/ /usr/local/mplayer/share/mplayer/font/
huang:/software/mplayer # mv font-arial-iso-8859-1/ /usr/local/mplayer/share/mplayer/font/
huang:/software/mplayer # mv font-arial-iso-8859-2/ /usr/local/mplayer/share/mplayer/font/
huang:/software/mplayer # mv font-arial-iso-8859-7/ /usr/local/mplayer/share/mplayer/font/
5. 安装皮肤
huang:/software/mplayer # tar xvf PowerPlayer-1.1.tar.bz2
huang:/software/mplayer # mv PowerPlayer default
huang:/software/mplayer # mv default/ /usr/local/mplayer/share/mplayer/Skin/
最后,字幕字体
找一个ttf字体文件,放到~/.mplayer/下面,并改名为subfont.ttf即可。
huang:/software/mplayer # ln -s /usr/local/mplayer/bin/mplayer /usr/local/bin/mplayer
huang:/software/mplayer # ln -s /usr/local/mplayer/bin/mplayer /usr/local/bin/gmplayer
使用gui则用gmplayer启动,否则使用mplayer即可
启动选项,-sub 跟字幕文件 -subcp cp936,也可以 -font 跟字体文件改变字幕字体。
2006年03月24日 星期五
最简单的中文latex配置
安装了SuSE 10系统自带的tex系统,可以在CJK环境下使用某些特定的字体类型,但是很多字体还是不能使用。
以下是一个非常简单的解决办法:
1.到王垠主页
http://learn.tsinghua.edu.cn:8080/2001315450/programs.html
下载了gbkfonts的可执行文件,只要gbkfonts的那个静态链接文件就可以了。
cp gbkfonts /usr/local/bin
chmod +x /usr/local/bin/gbkfonts
2. 建立texmf-local
不要直接放在/usr/share/texmf 下面,这样以后升级不方便。
因为~/texmf 目录默认是mktexlsr搜索的路径
mkdir ~/texmf
cd ~/texmf
gbkfonts /windows/C/windows/Fonts/simkai.ttf kai
gbkfonts /windows/C/windows/Fonts/simhei.ttf hei
...
其他字体用同样的方法生成。
3.
mv cjk.map dvips/config/ 这里会报没有dvips/config目录,新建一个就可以了。
cp /usr/share/texmf/dvips/config/config.ps dvips/config/
echo "p +cjk.map" >> dvips/config/config.ps
mv pdftex.cfg pdftex/config/
mktexlsr 最好用root执行一下
4. 测试代码
beat@huang:~/tex> cat testcjk.tex
\documentclass{article}
\usepackage{CJK}
\begin{document}
\begin{CJK*}{GBK}{hei}
这是黑体。
\end{CJK*}
\end{document}
然后latex testcjk.tex,dvipdfm testcjk.dvi就生成了相应的dvi和pdf文档。
2006年03月10日 星期五
Adobe Acrobat Reader 亚洲字体包 for Adobe Reader 7.0 under Linux
Adobe Acrobat Reader 亚洲字体包 for Adobe Reader 7.0 under Linux
下载地址:
http://download.adobe.com/pub/adobe/reader/unix/7x/7.0.5/misc/FontPack705_chs_i386-linux.tar.gz
2006年03月01日 星期三
2005年11月15日 星期二
Linux下常用压缩格式的压缩与解压
.tar
解包:tar xvf FileName.tar
打包:tar cvf FileName.tar DirName
(注:tar是打包,不是压缩!)
---------------------------------------------
.gz
解压1:gunzip FileName.gz
解压2:gzip -d FileName.gz
压缩:gzip FileName
.tar.gz 和 .tgz
解压:tar zxvf FileName.tar.gz
压缩:tar zcvf FileName.tar.gz DirName
---------------------------------------------
.bz2
解压1:bzip2 -d FileName.bz2
解压2:bunzip2 FileName.bz2
压缩: bzip2 -z FileName
.tar.bz2
解压:tar jxvf FileName.tar.bz2
压缩:tar jcvf FileName.tar.bz2 DirName
---------------------------------------------
.bz
解压1:bzip2 -d FileName.bz
解压2:bunzip2 FileName.bz
压缩:未知
.tar.bz
解压:tar jxvf FileName.tar.bz
压缩:未知
---------------------------------------------
.Z
解压:uncompress FileName.Z
压缩:compress FileName
.tar.Z
解压:tar Zxvf FileName.tar.Z
压缩:tar Zcvf FileName.tar.Z DirName
---------------------------------------------
.zip
解压:unzip FileName.zip
压缩:zip FileName.zip DirName
---------------------------------------------
.rar
解压:rar x FileName.rar
压缩:rar a FileName.rar DirName
rar请到:http://www.rarsoft.com/download.htm 下载!
解压后请将rar_static拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp rar_static /usr/bin/rar
---------------------------------------------
.lha
解压:lha -e FileName.lha
压缩:lha -a FileName.lha FileName
lha请到:http://www.infor.kanazawa-it.ac.jp/~ishii/lhaunix/下载!
>解压后请将lha拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp lha /usr/bin/
---------------------------------------------
.rpm
解包:rpm2cpio FileName.rpm | cpio -div
---------------------------------------------
.deb
解包:ar p FileName.deb data.tar.gz | tar zxf -
---------------------------------------------
.tar .tgz .tar.gz .tar.Z .tar.bz .tar.bz2 .zip .cpio .rpm .deb .slp
.arj .rar .ace .lha .lzh .lzx .lzs .arc .sda .sfx .lnx .zoo .cab .kar .cpt .pit .sit .sea
解压:sEx x FileName.*
压缩:sEx a FileName.* FileName
sEx只是调用相关程序,本身并无压缩、解压功能,请注意!
sEx请到: http://sourceforge.net/projects/sex下载!
解压后请将sEx拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp sEx /usr/bin/
2005年11月13日 星期日
编写Linux下的Daemon程序
编写Linux下的Daemon程序 作者: dagger 无崖阁 xyg.ods.org
版本: 1.0 2003-04-08 初始版本
一、引言 Daemon程序是一直运行的服务端程序,又称为守护进程。
本文介绍了在Linux下编写Daemon程序的步骤,并给出了例子程序。
二、Daemon程序简介 Daemon是长时间运行的进程,通常在系统启动后就运行,
在系统关闭时才结束。一般说Daemon程序在后台运行,是因为它没有控制终端,
无法和前台的用户交互。Daemon程序一般都作为服务程序使用,等待客户端程序
与它通信。我们也把运行的Daemon程序称作守护进程。
三、Daemon程序编写规则
编写Daemon程序有一些基本的规则,以避免不必要的麻烦。
1、首先是程序运行后调用fork,并让父进程退出。子进程获得一个新的进程ID,
但继承了父进程的进程组ID。
2、调用setsid创建一个新的session,使自己成为新session和新进程组的
leader,并使进程没有控制终端(tty)。
3、改变当前工作目录至根目录,以免影响可加载文件系统。或者也可以改变到
某些特定的目录。
4、设置文件创建mask为0,避免创建文件时权限的影响。
5、关闭不需要的打开文件描述符。因为Daemon程序在后台执行,不需要于终端
交互,通常就关闭STDIN、STDOUT和STDERR。其它根据实际情况处理。
另一个问题是Daemon程序不能和终端交互,也就无法使用printf方法输出信息
了。我们可以使用syslog机制来实现信息的输出,方便程序的调试。在使用
syslog前需要首先启动syslogd程序,关于syslogd程序的使用请参考它
的man page,或相关文档,我们就不在这里讨论了。
四、一个Daemon程序的例子 编译运行环境为Redhat Linux 8.0。
我们新建一个daemontest.c程序,文件内容如下:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <syslog.h>
#include <signal.h>
int daemon_init(void)
{ pid_t pid;
if((pid = fork()) < 0) return(-1);
else if(pid != 0) exit(0); /* parent exit */
/* child continues */
setsid(); /* become session leader */
chdir("/"); /* change working directory */
umask(0); /* clear file mode creation mask */
close(0); /* close stdin */
close(1); /* close stdout */
close(2); /* close stderr */
return(0); }
void sig_term(int signo)
{ if(signo == SIGTERM)
/* catched signal sent by kill(1) command */
{ syslog(LOG_INFO, "program terminated.");
closelog(); exit(0); }
}
int main(void)
{ if(daemon_init() == -1)
{ printf("can't fork self\n"); exit(0); }
openlog("daemontest", LOG_PID, LOG_USER);
syslog(LOG_INFO, "program started.");
signal(SIGTERM, sig_term); /* arrange to catch the signal */
while(1) { sleep(1); /* put your main program here */ }
return(0); }
使用如下命令编译该程序: gcc -Wall -o daemontest daemontest.c
编译完成后生成名为daemontest的程序,执行./daemontest来测试程序的运行。
使用ps axj命令可以显示系统中已运行的daemon程序的信息,包括进程ID、
session ID、控制终端等内容。
部分显示内容:
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1098 1101 1101 1074 pts/1 1101 S 0 0:00 -bash 1 1581 777 777 ? -1 S 500 0:13 gedit 1 1650 1650 1650 ? -1 S 500 0:00 ./daemontest 794 1654 1654 794 pts/0 1654 R 500 0:00
ps axj 从中可以看到daemontest程序运行的进程号为1650。
我们再来看看/var/log/messages文件中的信息: Apr 7 22:00:32 localhost
daemontest[1650]: program started.
显示了我们在程序中希望输出的信息。
我们再使用kill 1650命令来杀死这个进程,
/var/log/messages文件中就会有如下的信息:
Apr 7 22:11:10 localhost daemontest[1650]: program terminated.
使用ps axj命令检查,发现系统中daemontest进程已经没有了。
五、参考资料
Advanced Programming in the UNIX Environment W.Richard Stevens
Daemon是怎样练成的
守护进程
守护进程是生存期长的一种进程。它们独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事件。他们常常在系统引导装入时启动,在系统关闭时终止。unix系统有很多守护进程,大多数服务器都是用守护进程实现的。比如,网络服务inetd、Web服务http等。同时,守护进程完成许多系统任务。比如,作业规划进程crond、打印进程lqd等。
这里主要说明守护进程的进程结构,以及如何编写守护进程程序。因为守护进程没有控制终端,所以我们还要介绍在守护进程运行时错误输出的方法。
守护进程及其特性
守护进程最重要的特性是后台运行。在这一点上,DOS下的常驻内存程序TSR与之相似。
其次,守护进程必须与其运行前的环境隔离开来。这些环境包括未关闭的文件描述符、控制终端、会话和进程组、工作目录以及文件创建掩码等。这些环境通常是守护进程从执行它的父进程(特别是shell)中继承下来的。
最后,守护进程的启动方式有其特殊之处。它可以在系统启动时从启动脚本/etc/rc.d中启动,可以由inetd守护进程启动,可以有作业规划进程crond启动,还可以由用户终端(通常是shell)执行。
总之,除开这些特殊性以外,守护进程与普通进程基本上没有什么区别。因此,编写守护进程实际上是把一个普通进程按照上述的守护进程的特性改造成为守护进程。如果大家对进程的认识比较深入,就对守护进程容易理解和编程了。
首先我们来察看一些常用的系统守护进程,看一下他们和几个概念:进程组、控制终端和对话期有什么联系。p s命令打印系统中各个进程的状态。该命令有多个选择项,有关细节请参考系统手册。为了察看所需的信息,执行:
ps -axj
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
0 1 0 0 ? -1 S 0 0:04 init
1 2 1 1 ? -1 SW 0 0:00 [keventd]
1 3 1 1 ? -1 SW 0 0:00 [kapm-idled]
0 4 1 1 ? -1 SWN 0 0:00 [ksoftirqd_CPU0]
0 5 1 1 ? -1 SW 0 0:00 [kswapd]
0 6 1 1 ? -1 SW 0 0:00 [kreclaimd]
0 7 1 1 ? -1 SW 0 0:00 [bdflush]
0 8 1 1 ? -1 SW 0 0:00 [kupdated]
1 9 1 1 ? -1 SW< 0 0:00 [mdrecoveryd]
1 17 1 1 ? -1 SW 0 0:02 [kjournald]
1 92 1 1 ? -1 SW 0 0:00 [khubd]
1 573 573 573 ? -1 S 0 0:03 syslogd -r -x
1 578 578 578 ? -1 S 0 0:00 klogd -2
1 598 598 598 ? -1 S 32 0:00 portmap
进程号为1、2的这些进程非常特殊,存在于系统的整个生命期中。它们没有父进程ID ,没有组进程ID ,也没有对话期ID 。syslogd 守护进程可用于任何为操作人员记录系统消息的程序中。可以在一台实际的控制台上打印这些消息,也可将它们写到一个文件中。sendmail 是标准邮递守护进程。update 程序定期将内核缓存中的内容写到硬盘上(通常是每隔30 秒)。为了做到这一点,该程序每隔30 秒调用sync(2 )函数一次。cron 守护进程在指定的日期和时间执行指定的命令。许多系统管理任务是由cron 定期地使相关程序执行而得以实现的。inetd进程监听系统的网络界面,以输入对各种网络服务器的请求。最后一个守护进程,lpd 处理对系统提出的各个打印请求。
注意,所有守护进程都以超级用户(用户ID为0)的优先权运行。没有一个守护进程具有控制终端,终端名称设置为问号(?)、终端前台进程组ID设置为-1。缺少控制终端是守护进程调用了setsid的结果。除update以外的所有守护进程都是进程组的首进程,对话期的首进程,而且是这些进程组和对话期中的唯一进程。最后,应当引起注意的是所有这些守护进程的父进程都是init进程。
在接触实际编程前,我们来看看编写守护进程要碰到的概念:进程组合会话期。
进程组
每个进程除了有一进程ID之外,还属于一个进程组(在讨论信号时就会涉及进程组)进程组是一个或多个进程的集合。每个进程有一个唯一的进程组ID。进程组ID类似于进程ID——它是一个正整数,并可存放在pid_t数据类型中。
每个进程组有一个组长进程。组长进程的标识是,其进程组ID等于其进程ID,进程组组长可以创建一个进程组,创建该组中的进程,然后终止,只要在某个进程组中有一个进程存在,则该进程就存在,这与其组长进程是否终止无关。从进程组创建开始到其中最后一个进程离开为止的时间区间称为进程组的生命期。某个进程组中的最后一个进程可以终止,也可以参加另一进程组。
前面已经提到进程调用setgid可以参加一个现存的组或者创建一个新进程组(setsid也可以创建一个新的进程组,后面将用到)
会话期
会话期(session)是一个或多个进程组的集合。其中,在一个会话期中有3个进程组,通常是有shell的管道线将几个进程编成一组的。
下面说明有关会话期和进程组的一些特性:
一个会话期可以有一个单独的控制终端(controlling terminal),这一般是我们在其上登录的终端设备(终端登录)或伪终端设备(网络登录),但这个控制终端并不是必需的。
建立与控制终端连接的会话期首进程,被称之为控制进程(contronlling process)。以及一个会话期中的几个进程组可被分为一个前台进程组(foreground process group)以及一个或几个后台进程组(background process group)
如果一个会话期有一个控制终端,则它有一个前台进程组,其他进程组为后台进程组。无论何时键入中断键(常常是delete或ctrl-c)或退出键(通常是ctrl-\),就会造成将中断信号或退出信号送至前途进程组的所有进程。
守护进程的编程规则
在不同Unix环境下,守护进程的具体编程细节并不一致。但所幸的是,守护进程的编程原则其实都一样,区别仅在于具体的实现细节不同,这个原则就是要满足守护进程的特性。编程规则如下:
1、在后台运行
为避免挂起控制终端,要将daemon放入后台执行,其方法是,在进程中调用fork使父进程终止,让daemon在子进程中后台执行。具体就是调用f o r k ,然后使父进程e x i t 。这样做实现了下面几点:
第一,如果该精灵进程是由一条简单s h e l l 命令起动的,那么使父进程终止使得s h e l l 认为这条命令已经执行完成。
第二,子进程继承了父进程的进程组I D ,但具有一个新的进程I D ,这就保证了子进程不是一个进程组的首进程。这对于下面就要做的s e t s i d 调用是必要的前提条件。
2、脱离控制终端,登录会话和进程组
登录会话可以包含多个进程组,这些进程组共享一个控制终端,这个控制终端通常是创建进程的登录终端、控制终端,登录会话和进程组通常是从父进程继承下来的。我们的目的就是要摆脱它们,使之不受它们的影响。
其方法是在第一点的基础上,调用setsid()使进程成为会话组长:
需要说明的是,当进程是会话组长时,setsid()调用会失败,但第一点已经保证进程不是会话组长。setsid()调用成功后,进程成为新的会话组长和新的进程组长,并与原来的登录会话和进程组脱离,由于会话过程对控制终端的独占性,进程同时与控制终端脱离。
具体是操作就是:
(a )成为新对话期的首进程
(b )成为一个新进程组的首进程
(c )没有控制终端。
3、禁止进程重新打开控制终端
现在,进程已经成为无终端的会话组长,但它可以重新申请打开一个控制终端。可以通过使进程不再成为会话组长来禁止进程重新打开控制终端:
4、关闭打开的文件描述符
进程从创建它的父进程那里继承了打开的文件描述符。如不关闭,将会浪费系统资源,造成进程所在地文件系统无法卸下以及无法预料的错误。一般来说,必要的是关闭0、1、2三个文件描述符,即标准输入、标准输出、标准错误。因为我们一般希望守护进程自己有一套信息输出、输入的体系,而不是把所有的东西都发送到终端屏幕上。调用fclose();
5、改变当前工作目录
将当前工作目录更改为根目录。从父进程继承过来的当前工作目录可能在一个装配的文件系统中。因为精灵进程通常在系统再引导之前是一直存在的,所以如果精灵进程的当前工作目录在一个装配文件系统中,那么该文件系统就不能被拆卸。
另外,某些精灵进程可能会把当前工作目录更改到某个指定位置,在此位置做它们的工作。例如,行式打印机假脱机精灵进程常常将其工作目录更改到它们的s p o o l 目录上。
可以调用chdir(“目录”);
6、重设文件创建掩码
将文件方式创建屏蔽字设置为0 。由继承得来的文件方式创建屏蔽字可能会拒绝设置某些许可权。例如,若精灵进程要创建一个组可读、写的文件,而继承的文件方式创建屏蔽字,屏蔽了这两种许可权,则所要求的组可读、写就不能起作用。
7、处理SIGCHLD 信号
处理SIGCHLD信号并不是必需的。但对于某些进程,特别是服务器进程往往在请求到来时生产子进程出来请求。如果父进程不等待子进程结束,子进程将成为僵尸进程,(zombie)而仍占用系统资源。如果父进程等待子进程结束,将增加父进程的负担,影响服务器进程的并发性能。在系统V下可以简单的将SIGCHLD信号的操作设为SIG-IGN:
signal(SIGCHLD,SIG_IGN);
这样,内核在子进程结束时不会产生僵尸进程,这一点与BSD4不同,在BSD4下必须显示等 待子进程结束才能释放僵尸进程。
守护进程实例
守护进程实例包括两部分:主程序test.c和初始化程序init.c。主程序每隔一分钟向/tmp
目录中的日志test.log 报告运行状态。初始化程序中的init_daemon 函数负责生成守护进程
void make_daemon(void)
{
pid_t pid;
FILE * lockfd;
sigset_t sighup;
int i;
extern pid_t getsid(pid_t);
pid = fork();//第一个子进程生成
if (pid < 0) {
printinfo(”fork error!”,INFOERROR);
exit(FAILEXIT);
}else if (pid > 0) {
printinfo(”fork 1 ok! “, INFOSCREEN);
exit(OKEXIT);//退出父进程,摆脱shell的控制
}
pid = getpid();//获得子进程自身的id
lockfd = fopen(PIDFILE, “w”);//以下是将pid写入文件
if (lockfd != NULL) {
fprintf(lockfd, “%d\n”, pid);
fclose(lockfd);
}//写入pid
if (getsid(0) != pid) {//创建新的会话期
if (setsid() < 0) {
printinfo(”backupdaemon setsid error!”,INFOERROR);
perror(”setsid”);
}
}
if(pid=fork()){//再次生成子进程,这时候是孙子进程
exit(0);//退出上一代进程
}else if(pid<0){
exit(1);
}
close(1);//关闭文件
close(2);
chdir(rundir);//改变运行的目录
umask(022);//改变文件权限
}
守护进程的错误输出
守护进程不属于任何终端,所以当需要输出某些信息时,它无法像一般程序那样将信息直接输出到标准输出和标准错误输出中。我们很大时候也不希望每个守护进程将它自己的出错消息写到一个单独的文件中。因为对于系统管理人员而言,要记住哪一个守护进程写到哪一个记录文件中,并定期的检查这些文件,他一定会为此感到头疼的。所以,我们需要有一个集中的守护进程出错记录机制。目前很多系统都引入了syslog记录进程来实现这一目的。
自伯克利开发了BSD syslog并广泛应用以来,BSD syslog 机制被大多数守护进程所使用。我们下面介绍BSD syslog 的用法。有三种方法产生记录消息:
1 内核例程可以调用log函数。任何一个用户进程通过打开和读/dev/klog设备就可以读取这些消息。因为我们无意编写内核中的例程,所以不再进一步说明此函数。
2 大多数用户进程(守护进程)调用syslog函数以产生记录消息。我们将在下面说明其调用序列。这使消息发送至Unix域数据报套接口/dev/log。
3 在此主机上,或通过TCP/IP网络连接到此主机的某一其他主机上的一个用户进程可将记录消息发向UDP端口514。
注意:syslog 函数并不产生这些UDP数据报——它们要求产生此记录消息的进程具有显式的网络编程。
通常,syslog守护进程读取三种格式的记录消息。此守护进程在启动时读一个配置文件。一般来说,其文件名为/etc/syslog.conf,该文件决定了不同种类的消息应送向何处。例如,紧急消息可被送向系统管理员(若已登录),并在控制台上显示,而警告消息则可记录到一个文件中。该机制提供了syslog函数,其调用格式如下
#include <syslog.h>
void openlog (char*ident,int option ,int facility);
void syslog(int priority,char*format,……)
void closelog();
调用openlog是可选择的。如果不调用openlog,则在第一次调用syslog时,自动调用openlog。调用closelog也是可选择的,它只是关闭被用于与syslog守护进程通信的描述符。调用openlog 使我们可以指定一个ident,以后, 此ident 将被加至每则记录消息中。ident 一般是程序的名称(例如 ,cron ,inetd 等)。option 有4种可能:
LOG_CONS 若日志消息不能通过Unix域数据报发送至syslog,则将该消息写至控制台。
LOG_NDELAY1 立即打开Unix域数据报套接口至syslog守护进程,而不要等到记录第一消息。通常,在记录第一条消息之前,该套接口不打开。
LOG_PERROR 除将日志消息发送给syslog 外,还将它至标准出错。此选项仅由4.3BSDReno及以后版本支持。
LOG_PID 每条消息都包含进程ID。此选项可供对每个请求都fork一个子进程的守护进程使用。
在openlog中设置facility参数的目的是让配置文件可以说明,来自不同设施的消息以不同的方式进行处理。如果不调用openlog,或者以facility 为0来调用它,那么在调用syslog 时,可将facility作为priority参数的一个部分进行说明。调用syslog产生一个记录消息。其priority参数是facility和level的组合,它们可选取的值分别列于下面。level值按优先级从高级到最低按序排列。
2005年10月23日 星期日
SuSE Linux安装chm文件阅读软件
Linux默认安装不支持阅读chm格式的文件,但是有许多文档以chm格式发布,是个很头疼的问题。
经过google搜索发现可以安装几个类似的软件,比如chmsee,chmviewer,xchm等等。网上介绍认为xchm是个不错的选择。以下是我安装的过程:
从sourceforge上下载xchm1.2源代码,下载地址:
http://sourceforge.net/project/showfiles.php?group_id=87007
安装xchm需要两个包支持,一个是 wxGTK,另一个是 chmlib。
下载wxGTK的地址是:http://www.wxwidgets.org/
下载chmlib的地址是:http://66.93.236.84/%7Ejedwin/projects/chmlib/
分别是:wxWidgets-2.6.2.tar.gz和chmlib-0.36.tgz。
安装wxGTK的过程没有问题,只需要tar configure make make install就可以了
安装chmlib-0.36.tgz时配置编译均没有问题,但是make install的时候不能把库文件拷到/usr/lib或/usr/local/lib下面。需要手动把src/.libs生成的库文件拷到相应目录下面。
然后ldconfig
然后解压 xchm-1.2.tar.gz并按正常过程安装。
之后可以查看chm文件了。不过不幸的是xchm只能看英文文档,中文文档无法正确显示。
然后我选择继续安装chmsee-0.9.5,源码下载地址:http://linuxfire.dhis.org/~zhong/
chmsee需要安装libgtkhtml,我已事先安装了 gtkhtml3.8_3.8.1。
tar -xvf chmsee-0.9.5.tar.bz2
./configure
配置过程中报找不到gtkhtml-3.1
解决方案:
ln -s /usr/local/lib/pkgconfig/libgtkhtml-3.8.pc /usr/local/lib/pkgconfig/libgtkhtml-3.1.pc
然后./configure
make
make install
一切ok。可以正常阅读chm文件了,只需要在chmsee启动时选择编码就可以了。
2005年10月21日 星期五
Acrobat Reader7 中文支持
SuSE Linux 10.0 默认安装了Adobe Reader 7.0.1-4,但是不能支持中文pdf文档阅读。目前Adobe官方网站并没有给出Adobe Reader 7.x for Linux的亚洲语言字体包。
我的解决方案是:从Adobe官方网站下载Adobe Reader 5.x for Unix的亚洲语言字体包,chsfont.tar.gz,
下载地址:ftp://ftp.adobe.com/pub/adobe/acrobatreader/unix/5.x/chsfont.tar.gz
tar -zxvf chsfont.tar.gz
cd CHSKIT/
tar -xvf LANGCHS.TAR
tar -xvf LANGCOM.TAR
把所有解压后的所有文件拷贝到 /usr/X11R6/lib/Acrobat7/Resource/CMap/即可。
安装prozilla,多线程下载加速软件
源码下载地址http://prozilla.genesys.ro/downloads/prozilla/tarballs/,我下载的版本是prozilla-2.0.0-r1.tar.gz
tar -zxvf prozilla-2.0.0-r1.tar.gz
cd prozilla-2.0.0-r1/libprozilla/src/
vi Makefile.in //此发行版的makefle有个小问题
删除第114行
includedir = $(prefix)/include行末的一个空格
cd ../..
./configure --prefix=/usr/apps/prozilla/
make
make install
ln -s /usr/apps/prozilla/bin/proz /usr/bin/proz
使用方法:
Usage: proz [OPTIONS] file_url
Ex: proz http://gnu.org/gnu.jpg
Options:
-h, --help Give this help
-r, --resume Resume an interrupted download
-f, --force Never prompt the user when overwriting files
-1 Force a single connection only
-n, --no-netrc Don't use .netrc, get the user/password
from the command line,otherwise use the
anonymous login for FTP sessions
--no-getch Instead of waiting for the user pressing a key,
print the error to stdout and quit
--debug Log debugging info to a file (default is debug.log)
-v,--verbose Increase the amount of information sent to stdout
--no-curses Don't use Curses, plain text to stdout
Directories:
-P, --directory-prefix=DIR save the generated file to DIR/
FTP Options:
--use-port Force usage of PORT insted of PASV (default)
for ftp transactions
Download Options:
-s, --ftpsearch Do a ftpsearch for faster mirrors
--no-search Do a direct download (no ftpsearch)
-k=n Use n connections instead of the default(4)
--timeout=n Set the timeout for connections to n seconds
(default 180)
-t, --tries=n Set number of attempts to n (default(200), 0=unlimited)
--retry-delay=n Set the time between retrys to n seconds
(default 15 seconds)
--max-bps=n Limit bandwith consumed to n bps (0=unlimited)
FTP Search Options:
--pt=n Wait 2*n seconds for a server response (default 2*4)
--pao=n Ping n servers at once(default 5 servers at once)
--max-ftps-servers=n Request a max of n servers from ftpsearch (default 40)
--min-size=n If a file is smaller than 'n'Kb, don't search, just download it
--ftpsid=n The ftpsearch server to use
(0=filesearching.com
1=ftpsearch.elmundo.es
Information Options:
-L, --license Display software license
-V, --version Display version number
ProZilla homepage: http://prozilla.genesys.ro
Please report bugs to <prozilla@genesys.ro>
2005年10月14日 星期五
SuSE10调整屏幕偏移和分辨率
在我的机器上装SuSE10以后,进入gnome桌面环境后,屏幕是偏向右侧的。如果这时用显示器下面的自动调整的话,可以调整到合适的状态,但是回到console模式下面就向左偏移了。修改方法是:
1.在console模式下自动调整到最佳位置;
2.startx进入X环境,命令行xvidtune进行调整(这时,可以用显示器的自动调整键),调整好以后,点xvidtune的show按钮,在终端中会显示以下类似信息:
[18:13:28 @Huang ~]#xvidtune
Vendor: --> VESA, Model: 1024X768@60HZ
Num hsync: 1, Num vsync: 1
hsync range 0: 31.00 - 48.00
vsync range 0: 50.00 - 60.00
"1024x768" 65.00 1024 1064 1200 1344 768 771 777 806 -hsync -vsync
3.修改文件/etc/X11/xorg.conf
找到Section "Modes"的位置,添加或修改一行Modeline 为上面得到的数字,并将其他Modeline行注释或删掉,得到类似下面的结果:
Section "Modes"
Identifier "Modes[0]"
Modeline "1024x768" 65.0 1024 1064 1200 1344 768 771 777 806 -hsync -vsync
#Modeline "1024x768" 61.89 1024 1080 1184 1344 768 769 772 794
EndSection
保存,退出。
退出X环境重新进入就可以了。
2005年10月13日 星期四
提示符
\u - 当前用户的用户名(=$LOGNAME)
\h - 运行shell 的计算机名(hostname)
\H - 完整的计算机名
\W - 当前工作目录名
\w - 当前工作命令全路径名
\$ - 对于普通用户显示$ ,对于超级用户显示#
\! - 当前命令的历史编号
\# - 当前命令编号(在当前的shell 下运行的命令)
\d - 当前日期
\t - 当前时间(24 小时制)
\T - 当前时间(12 小时制),bash 2.0 有效
\@ - 当前时间(AM/PM 格式),bash 2.0 有效
\s - shell 的类型
\a - 告警声音
\j - 用户的任务数
\n - 新行
\\ - 反斜杠
\[ - 不可打印字符开始标志
\] - 不可打印字符结束标志
\nnn - ASCII 字符对应的八进制数值
$(date) - date (输出当前日期)命令输出或者其他的命令
2005年10月10日 星期一
SSH权威指南
第一章 SSH简介
ssh(secure shell)是一种通用,功能强大的基于软件的网络安全解决方案,计算机每次向网络
发送数据时,SSH都会自动对其进行加密。数据到达目的地时,SSH自动对加密数据进行
解密。整个过程都是透明的。它使用了现代的安全加密算法,足以胜任大型公司的任务繁重
的应用程序的要求。
SSH协议内容涉及认证AUTHENTICATION,加密ENCRYPTION,和网络上传输数据的完整
性INTEGRITY。
SSH特性概述
1、远程登录
$ ssh -l root host.example.com
2、安全文件传输
$ scp myfile metoo@secondacount.com
3、安全执行远程命令,能确保传输的数据安全。
4、密钥和代理
基于密钥的认证方法不用记住多个帐号密码。
5、访问控制,能授权别人访问自已帐号。
6、端口转发
$ ssh -L 3002:localhost:119 xxx.xxx.com
相关安全技术
rsh命令族,rsh,rlogin and rcp。连接不加密,认证模型十分脆弱。
PGP加密程序。它是基于文件的。
Kerberos认证系统,用于网络可能被监视,而且计算机不是中心控制的环境。基于麻省理工
学院的Athena项目。它SSH不是,SSH是轻量级的,容易部署。Kerberos使用前必须构建
一些重要基础。
IPSEC,Internet安全协议。
SRP,安全远程密码协议,是Stanford大学开发的。是一种专用的认证协议。
SSL,安全套接字。
stunnel,是一种SSL工具,它为UNIX环境现有的基于TCP的服务(POP,IMAP等)增加
SSL保护,而不用修改服务器源程序。
第二章 SSH客户端的基本用法
最常用功能,1、经由安全连接登录到远程计算机。2、通过安全连接在计算机间拷贝文件。
当你第一次连接SSH服务器时,出现问答时要回答“yes”,把已知名主机的密钥的公共部
分拷贝一份存在本地。之后你每次连接这台服务器,就用这个公钥来验证远程主机。最好是
能在首次连接前就能获得这个公钥,否则第一次连接服务器时你可能已受到中间人攻击。
使用密钥进行认证,SSH支持公钥认证,可以使用加密密钥,密钥比密码更安全。
SSH证书使用一对密钥,一个私钥,一个公钥,私钥只保存你独有的一些秘密信息。SSH
用其向服务器证明自已的身份。公钥是公开的,可以随便将其放入SSH服务器上自已的帐
号中,在认证时,进行私钥和公钥协商,如果匹配,那么身份就得以证明,认证就成功。
在使用公钥认证以前,首先要进行一些设置:
1、需要一对密钥,还需要使用一个口令来保护自已的私钥。
使用ssh-keygen程序生成一对密钥。如果不存在SSH目录,程序为自动创建本地SSH目录
~/.ssh,并将所生成的密钥分成两个文件存储,公有部份identity.pub,私有部分identity,或
id_dsa_1024_a,id_dsa_1024_a.pub(ssh2)。
2、需要在SSH服务器上安装自已的公钥。
通过配置SSH目录中的一个文件实现,对于SSH1 AND OPENSSH来说该文件是
~/.ssh/authorized_keys。对SSH2来说是~/.ssh2/authorization。OPENSSH中的SSH-2连接自
3.0版本起也一同使用authorized_keys文件。3.0版本前的使用authorized_keys2。把用户本
地机器生成identity.pub文件内容加入其中。对SSH2来说,用户需编辑两个文件,一个客
户端一个在服务器端,
在客户端,要创建或编辑文件~/.ssh2/identification并在其中插入一行,说明自已的私钥文件
名: IdKey id_dsa_1024_a.
在服务器端,要创建或编辑文件~/.ssh2/authorization,该文件包含有公钥信息,每行一个,
但和SSH1的authorized_keys文件不同(authorized_keys中包含有公钥的拷贝),authorization
中只给出公钥文件名:Key id_dsa_1024_a.pub。最后,把这个文件从本地机器上拷贝到服务
器~/.ssh2中。为安全起见,要确保ssh目录的安全,只有所有者才有权写入。如果远程用户
的SSH配置文件的权限设置不当,服务器可能会拒绝进行认证。
公钥认证比密码认证更安全,因为:
1、 公钥认证需要两个加密部份(磁盘上的identify文件和用户头脑中的口令),入侵都必须
2、 具备两种条件才行。密码认证只需要一个部份,那就是密码,它可能更容易被窃取。
3、 在公钥认证中,口令和密钥都不用发给远程主机,只要把前面讨论的认证者发给远程主
4、 机就可以了,因此,并没有秘密信息传出客户端。
3、机器生成的密钥是不可能猜测出来的,而人生成的密码容易受到字典攻击。
通过禁用密码认证并只允许使用密钥认证能极大提高主机的安全性。
如果要修改密钥
如果已经生成一个密钥对,并把公钥拷贝到多个SSH服务器上了,用户有一天决定修改自
已的身份,因为再运行ssh-keygen。这样,就会覆盖identify and identify.pub文件,用户之
前的公钥就没用了,必须把新公钥再次拷贝到各个服务器上。这是很头疼的,所以建议:
1、 不能局限于仅仅使用一个密钥对,可随意生一此密钥对,将其保存在不同的文件中,并
2、 将其用作不同的用途。
3、 如果只是想修改口令,就不必重新生成一个密钥对,ssh-keygen有一个命令行选项可以
4、 替换现有的密钥口令。ssh1 and openssh是-p,对于ssh2是-e。这样,因为私钥没变,所以
5、 公钥依然不效,中需使用新口令对私钥进行解密就可以了。
ssh代理
它可以把私钥保存在内存中,为认证提供服务,不用重复输入密码。直到用户退出为止。代
理程序是ssh-agent。可手工运行也可编辑~/.login 或~/.xsession来自动运行。
$ ssh-agent $SHELL 其中SHELL是用户登录shell的环境变量。运行该命令后,打开另外
一个shell,在这个shell中可以访问代理。
接着用ssh-add命令装入私钥。这样,使用ssh and scp命令就不用再提醒输入口令了。口令
装入内存中。如果用户正运行x window系统,并设置了DISPLAY环境变量,而标准输入
不是终端,那么ssh-add就使用一个图形化X程序ssh-askpass来读取口令。要强制ssh-add
使用X来读取口令,请在命令行中输入ssh-add < /dev/null。
-l 参数显示内存中的密钥
-d 参数从代理中删除密钥 $ ssh-add -d ~/.ssh/id_xxx.pub
-D 是删除所有密钥
-t 对加载的密钥设置超时时间,超时代理将自动卸载密钥。
-L -U 对代理进行加锁和解锁,当你离开计算机而不想退出登录时有用。
代理转发
可能通过代理转发功能,可以用SCP把文件从远程SSH服务器上拷贝到第三方SSH主机上。
条件是你在第三方SSH主机上必须有一个帐号。具体操作是这样的:
1、 在本地主机上运行命令:# scp pat@shell.isp.com:print-me
2、 psmith@other.host.net:other-print-me
2、这个scp进程与本地代理进行联系,并让用户和shell.isp.com进行认证。
3、自动在shell.isp.com上执行第二个scp,用来把文件拷贝到other.host.net主机上。
3、 由于启用了代理转发(SSH1 AND SSH2默认是打开的,openssh默认是关闭的),因此
4、 shell.isp.com上的SSH服务器就充当一个代理。
5、第二个scp进程通过联系shell.isp.com上的代理试图让用户和other.host.net进行认证。
5、 shell.isp.net上ssh服务器秘密与用户的本地代理进行通信,从而构建出一个认证者来提
6、 供用户的证书并将其传回服务器。
7、服务器为第二个scp进程验证用户的身份,other.host.net上的认证获得成功。
8、开始拷贝文件。
由于代理转发不会把私钥发送到远程主机上,而是把认证返回第一台机进行处理,因此密钥
是安全的。
不用密码或口令进行连接方式
1、使用代理的公钥认证。
2、可信主机认证。
3、Kerberos认证。
在后文中将会讨论这些方式的优缺点。
sftp
它是在SSH上的一个独立文件传输工具,操作与ftp类似,可以在一个会话中调用多个命令
进行文件拷贝和处理,而scp每次调用时都要打开一个会话。sftp不区分ascii and binary传
输模式,只使用二进制模式,因此,如果使用它在windows and unix之间拷贝ascii文件,
那么就不能正确转换行结束符。
第三章 SSH内幕
SSH协议的主要特性和优点:
1、 使用强加密技术来保证数据的私密性。端到端通信用随机密钥进行加密,随机密钥为会
话进行安全协商,会话结束后被丢弃。支持的算法有ARCFOUR,Blowfish,DES,IDEA,3DES等。
2、通信完整性,确保通信不会被修改。SSH-2基于MD5 AND SHA-1的加密hash算法。
3、认证,即发送者和接收者的身份证明。客户机和服务器双向认证。
4、授权,即对账号进行访问控制。
5、使用转发或隧道技术对其它基于tcp/ip的会话进行加密。支持三种转发,tcp端口转发,
X转发,代理转发。
SSH可以防止的攻击
1、网络窃听,SSH通信是加密的,即使截获会话内容,也不能将其解密。
2、名字服务和IP伪装,SSH通过加密验证服务器主机身份可避免这类风险。
3、连接劫持,SSH的完整性检测负责确定会话在传输过程是否被修改,如果被修改过,就
关闭连接。
4、 中间人攻击,SSH利用两种方法防止这种攻击,第一种是服务器主机认证。除非攻击者
已经成功攻击了服务器主机,获得服务器的私有主机密钥。第二种是限制使用容易受到
这种攻击的认证方法,密码认证容易受到中间人攻击,而公钥和基于主机的/RhostsRSA
则对中间人攻击可以免疫。
5、插入攻击,这种攻击可以客户和服务器之间发送的正文数据流之间插入任意数据。ssh1
1.2.25后和openssh的所有版本都专门进行了设计,来检测并防止这种攻击。这种检测程序
增大了插入攻击的难度,但是并不能完全防止。ssh2使用强加密完整性检测手段来防止这个
问题。可以用3DES算法来防止这种攻击。
SSH不能防止的攻击
1、 密码崩溃,密码认证是一种脆弱的认证形式,尽量使用公钥认证方式。如果必须要密码
认证,可考虑使用S/Key之类的一次性密码机制。
2、 IP AND TCP攻击,由于SSH是在TCP之上进行操作的,因此容易受到针对TCP和IP
缺陷而发起的攻击。SYN flood,TCP不同步和TCP劫持等。只能通过更低层的防护措施
来保护。
3、流量分析。
4、隐秘通道。
5、粗心大意。安全是一个过程,而不是一个产品,不要认为装上SSH就安全了。
第四章 SSH的安装和编译时配置
第五章 服务器范围的配置
sshd可以在三个层次上进行配置,第一层次是上面的安装和编译时配置;第二层次是本章的
服务器范围配置;第三层次是每账号配置(第八章),前者是服务器编译时就指定了包含哪
些特定功能,不包含哪些功能,后者则是由终端用户来修改自已账号所使用的服务器的行为。
以普通用户身份运行SSH服务器
1、得到管理员许可。
2、生成一个主机密钥。
$ ssh-keygen -N '' -b 1024 -f ~/myserver/hostkey 生成hostkey and hostkey.pub两个文件
3、选择端口号。 要选择大于或等1024的端口,因为只有超级用户才有权使用小于
1024的端口 。
4、创建服务器配置文件(可选) 可创建自已的配置文件,否则,服务就使用内建的特性或使
用服务器范围的配置文件。
启动服务器方式:$ sshd -h ~/myserver/hostkey -p 2345 -f ~/myserver/config
由普通用户运行的服务器有一些缺点:
1、由于不是由root的uid下运行,因此只能连接到用户自已的账号上。
2、它需手工调用,不能自启动。
3、 日志用户没权看到,因为服务器把它写到syslog日志系统中,但可用调试模式运行服务
4、 器,这样信息就显示在终端机上。
服务器配置文件
SSH1 AND OPENSSH的配置文件通常是/etc/sshd_config,而SSH2的配置文件通常是
/etc/ssh2/sshd2_config。
以非缺省的配置文件来调用sshd,可以使用命令 -f 选项。$ sshd -f /usr/local/ssh/my_config。
以*号作为标号的语名都会被sshd忽略。
修改完配置后,修改不会马上影响到服务器,可重启服务器或发送SIGHUP信号。$ kill -HUP
`cat /etc/sshd.pid`
如果在命令行改动了配置,用SIGHUP信号重启服务器不能覆盖命令行的配置,它的优先
级高。
主机密钥,sshd主机密钥向SSH客户端唯一地标识SSH服务器。主机密钥保存在一对文件
中,一个文件包含私钥,一个文件包含公钥。对于SSH1 AND OPENSSH,它是
/etc/ssh_host_key。文件位置可用HostKey关键字修改 HostKey /usr/local/ssh/key。服务器的
公钥保存在.pub文件中。
OPENSSH服务器有一个SSH-2的主机密钥,缺省是在/etc/ssh_host_dsa_key。其位置可用
HostDsaKey /usr/local/openssh/key2修改。
对于SSH2,如果服务器是由超级用户运行,缺省私钥文件是/etc/ssh2/hostkey。如果是其它
用户运行,则在~/.ssh2/hostkey。可用HostKeyFile /etc/local/ssh/key修改。公钥是hostkey.pub
文件,可用publicHostKeyFile关键字修改。
可以用命令行选项指定私钥文件:$ sshd -h /usr/local/ssh/key。
随机数种子文件
如果用户的系统中有一个随机位源,如/dev/urandom,那么OPENSSH就不能创建随机数种
子文件。
服务器配置文件
通常是/etc/sshd_config /etc/ssh2/ssh2_config,可以用-f 选项重新指定其配置文件。可用于一
台机器运行多个sshd的情况。
每账号认证文件。~/.ssh/authorized_keys 。
文件权限
由于配置文件的权限设置错误,会降低系统的安全性,所以可以设置StrictModes YES/NO
关键字,对sshd的重要文件和目录的权限进行检查,如果检查失败,服务器就拒绝对该用
户的SSH连接。
在多宿主主机上,使用ListenAddress xxx.xxx.xxx.xxx来限制SSH只监听一个网络接口。
空闲连接时间,IdleTimeout xx 如果是0代表什么都不做,保持连接。否则,超时就断开连
接,可以用s,m,h,d,w表示。
KeepAlive YES/NO 可以断开失效的连接,比如客户端崩溃。
失败的登录
LogingGraceTime 60 限定用户必须在60秒内成功进行认证。 0值表禁用。命令行选项用
-g
PasswordGuesses 5 如果连接请求使用密码认证,那么sshd2就只允许客户端尝试五次。
(SSH2)
限制并发连接
MaxConnections 32 最大32个连接(SSH2)
逆向IP映射
SSH2服务器可以根据客户端地址进行逆向DNS查询,以确保客户端的地址就是这个地址。
如果检查失败,连接拒绝。
RequireReverseMapping yes (ssh2)
转发
AllowTcp-Forwarding yes
X11Forwarding yes
服务器密钥生成
该密钥用来对客户端/服务器之间的通信进行保护。是临时的,永远不会保存在磁盘上。服
务器在启动时生成这个密钥。并以固定的周期重新生成。缺省长度是768位,最小为512,
可以ServerKeyBits 2048 指定长度。用KeyRegenerationInterval 1200指定周期。 命令行选
项:-k
加密算法
Ciphers any 允许所有支持算法。其它算法包括
3des-cbc,blowfish-cbc,twofish-cbc,arcfour,none
mac算法
MAC关键字可以让用户选择sshd2进行完整性检测所使用的算法,称为消息认证代码。用
于sshd2的有hmac-sha1,hmac-md5,hmac-md5-96。
在OPENSSH中,用户可以用Protocol关键字选择支持SSH-1 AND SSH-2,1 代表SSH-1,2 代
表SSH-2, 1,2 代表都支持。
允许用户登录:认证和访问控制
1、认证负责对发起连接请求的用户的身份进行验证。
密码认证
PasswordAuthentication yes AllowedAuthentications password (ssh2)
公钥认证
RSAAuthentication yes (ssh1,openssh/1)
AllowedAuthentications publickey (ssh2)
DEAAuthentication yes (openssh/2)
Rhosts认证,可信主机认证通过检查远程主机名和相关用户名来实现对客户端的身份认证。
RhostsAuthentication yes (ssh1,openssh)
IgnoreRhosts yes (ssh1,ssh2,openssh)不使用系统的hosts.equiv and ~/.rhosts,使用SSH专用
的/etc/shosts.equiv and ~/.shosts
强可信主机认证。
RhostsRSAAuthentication yes ssh1,openssh
AllowedAuthentications hostbased ssh2
提取已知名主机的公钥
UserKnownHosts no ssh2
IgnoreUserKnownHosts yes openssh
PGP认证
Kerberos认证
S/key认证
SecurID认证
PAM认证
2、访问控制负责允许或禁止来自特定用户、机器在或INTERNET域的SSH连接到服务器
上。
通常,只要设置正确,任何账号都可以接收SSH连接,这种访问权限可以使用服务器关键
字AllowUsers and DenyUsers覆盖。
AllowUsers smith
如果配置文件中单独出现一个AllowUsers,后面没有任何内容,就表示禁止所有没提到的用
户连接,如果没有AllowUsers这个关键字,则所有用户都可连接。DenyUsers表示禁止连接。
可用通配符,
可以用组访问控制AllowGroups DenyGroups
主机名访问控制
AllowHosts hostname
DenyHosts hostname
超级用户的访问控制
sshd对超级用户专门使用一种特殊的访问机制,PermiRootLogin来允许或禁止使用SSH来
访问root账号。
显示用户的欢迎信息
PrintMotd yes/no default is yes
显示邮件信息
CheckMail yes/no default is yes
空密码
PermitEmptyPasswords yes/no 如果使用密码认证,并且有个账号没有设定密码,那么服务
器就可以拒绝访问这个账号
如果系统中存在/etc/nologin,那么sshd就只允许root用户登录,其它都不能登录。因此,touch
/etc/nologin是把访问权只授给系统管理员的一种快速方法。这样并不需要重新配置ssh。也
不需要重启ssh。
子系统
定义和调用远程命令的一个抽象层,用户可以通过在客户端命令行中给出命令来调用远程命
令,如:ssh server.examply.com /bin/tar c /home 这个命令调用tar,远程把/home拷贝到磁带上。
子系统是服务器机器上预定义的一组远程命令,这样就可以方便地执行。在服务器配置文档
中定义:subsystem backups /bin/tar c /home,要在服务器上运行该命令,可以使用 -s 选项。
ssh -s backups server.example.com。缺省情况下,sshd_config中定义了一个子系统,subsystem
sftp 。不要删除这个子系统,这是scp2和sftp必须的。
日志
Fascisl Logging mode 把调试信息打印到系统日志文件中,可以使用FascistLogging关键字
启用。
调试模式 可以使用-d命令选项启用
安静模式 只能输出严重错误,而不能输出 普通日志,可以使用QuietMode关键字或-q
命令行启用。
openssh中的日志配置关键字是SyslogFacility and LogLevel。SyslogFacility设置syslog的
facility(KERN,DAEMON,USER,AUTH,MAIL等),LogLevel记录日志提供的详细程度,该
值从低到高顺序是:QUIET,FATAL,ERROR,INFO,VERBOSE,DEBUG,使用DEBUG会侵犯用
户的隐私权,这个级别只能用于诊断,而不能用于普通操作。
第六章 密钥管理与代理
一个身份标识由两部份组成,分别称为私钥(Private Key)和公钥(Public Key),合称一个
密钥对。
SSH1,SSH2 AND OPENSSH身份标识文件的格式各不相同。
SSH1缺省设置中,私钥存储在文件identity中,公钥存储在文件identity.pub中。这个密钥
对存放在~/.ssh目录下,在使用前,把公钥拷贝到服务器上的一个认证文件里,如SSH1 AND
OPENSSH中的~/.ssh/authorized_keys,此后,当客户请求连接到你的服务器上的帐号时,就
会用一个私钥作为证明身份的标识,服务器则在authorized_keys文件中寻找与之匹配的公
钥。
SSH2密钥对文件的命名通常是根据该密钥使用的加密算法的性质来起的,例如一个用DSA
加密的1024位密钥生成时其缺省文件名是id_dsa_1024_a and id_dsa_1024_a.pub。用户必须
把私钥放在identification文件中,缺省是~/.ssh2/目录,一个私钥在这个文件中占一行,在公
钥认证中,每一行的开头都有一个关键字IdKey,后跟一个私钥文件名。如:
IdKey id_dsa_1024_a
IdKey my-other-ssh2-key
在服务器端的认证文件~/.ssh2/authorization中,SSH2不包含公钥的实际拷贝,只是把公钥
文件列出来,前面用关键字kEY标识。如:
Key id_dsa_1024_a.pub
Key something-else.pub
这样维护起来更容易,更方便。
OPENSSH对SSH-1连接使用的标识和授权文件与SSH1完全相同,对于SSH-2连接,缺省
的密钥则存储在~/.ssh/id_dsa(private key)和~/.ssh/id_dsa.pub(public key)中,服务器上的授权
文件是~/.ssh/authorized_keys。
创建身份标识用ssh-keygen命令。
OPENSSH的ssh-keygen可以支持SSH1中相应程序的所有功能和选项,它还新增了为SSH-2
连接生成DSA密钥的能力。
$ ssh-keygen -t dsa -b 1024
-e -x 选项可把OPENSSH格式的密钥存储格式转换成SSH2格式 (直接回车,按提示输入转
换文件名)
-i -X 选项把SSH2格式的密钥转换成OPENSSH格式。这样可用SSH2客户端连接
OPENSSH服务器。(直接回车,按提示输入转换文件名)
-y 如果不小心删掉了OPENSSH的公钥,可用-y恢复。
-l 可计算出公钥的指纹,指纹是鉴别位置不同的两个密钥是否相同的常用的一种密码学技
术。这项技术用于不可能逐位对比两个密钥的情况。OPENSSH AND SSH2都能计算指纹。
它是根据密钥计算出来一个长度较短的值,它是原理与校验和类似,用于验证一串信息(在
我们的例子中是密钥)的不可替换性。
启动代理
1、单shell方式,使用当前登录的shell. $ eval `ssh-agent`
2、子shell方式,派生出一个子shell,并继承父shell的某些环境变量。 $ ssh-agent $SHELL
不要想当然运行 $ ssh-agent,这样客户端是无法有代理联系的。删除代理用kill命令就可以
了。
SSH-1 与 SSH-2代理的兼容性
SSH-1的代理不能处理SSH-2的代理,SSH-2的代理却可以处理SSH-1的代理请求。
第七章 客户端的高级用法
$ ssh -a -p 220 -c blowfish -l sally -i myself server.example.com 可通过配置文件简化命令
输入
Host myserver
ForwardAgent no
Port 220
Cipher blowfish
User sally
IdentifyFile myself
HostName server.example.com
配置了该文件后,就可以在客户端简单地输入
$ ssh myserver
全局文件和本地文件
全局文件通常是由管理员创建的,用来维护整台计算机上的客户行为。该文件通常位于
/etc/ssh_config or /etc/ssh2/ssh2_config。每个客户也可以在自已账号中创建本地客户配置文
件,通常是~/.ssh/config or ~/.ssh2/ssh2_config。本地配置文件优先级高于全局配置文件。命
令行选项的优先级又高于本地配置文件。
scp有关命令参数
-r 递归拷贝目录
-p 保持文件权限和时间戳
-u 拷贝完成后删除源文件
-d 防止覆盖文件
-n 描述操作
-q 不显示统计信息
第八章 每账号服务器配置
这种配置可以让SSH服务器区分每个服务器上的各个用户。利用服务器目标账号的认证文
件(authorized_keys)配置。局限有两点,它不能覆盖编译时配置和服务器范围配置所采用
的安全措施,第二,如果使用公钥认证,每账号配置是十分灵活的,如果采用可信主机和密
码认证,提供的选择范围就很小。
基于公钥的配置
1、认证文件的完全格式 依次包含三项内容,一些选项,公钥和注释。多个选项用逗号分
开。
2、用于限制客户端可以在服务器上调用的程序的强制命令。如客户端请求执行/bin/ls命令,
而服务器端强制命令却运行/bin/who命令,它十分有用,可用于加强安全性,了为授权提供
方便。如要让你的助手每次连接上来都运行email命令程序pine,则可以这样:
command= "/usr/local/bin/pine" ...key...。最多可给每个密钥关联一个强制命令,要关联多个命
令可把这些命令放入远程主机的一个脚本中,并将该脚本作为强制命令运行。如果强制命令
有shell出口,那会存在安全问题,等于没有强制,客户可以运行任何程序。以下规则可以
用来判断一个程序是否适合用作强制命令。
a、 避免使用具有shell出口的程序(如:文件编辑器vi,Emacs; 分页程序 more,less;调用分
b、 页的man,新闻阅读程序rn,邮件阅读程序pine以及调试程序adb,非交互的程序find,xargs
c、 等)。
b、避免使用编译器,解释器或其它可以让用户生成并运行任意执行代码的程序。
c、可创建或删除文件的程序,如cp,mv,rm,scp,ftp等。
d、避免使用setuid or setgid的程序,特别是setuid 是root的程序。
d、 如果使用脚本作为强制命令,就要遵循编写安全脚本的传统规则,在一个脚本之内,要
限制使用相对路径作为搜索路径,应该使用绝对路径来调用所有的程序;不要盲目地把
用户提供的字符串作为命令来执行;不要让脚本执行任何setuid的工作。不要调用具有
shell出口的程序。
e、考虑使用受限shell。
f. 为一个单独的、专用的SSH密钥(不要用你登录的那个密钥)关联一个强制命令。这样
不会影响你的登录能力就可以方便地禁用该密钥。
g、禁用不必要的SSH特性。如no-port-forwarding,no-agent-forwarding,no-pty(禁用tty分配)。
几个常用的强制命令介绍:
使用定制消息拒绝连接:command="/bin/echo Sorry,buddy,but you've terminated!" ...key... 千万
不要用more and less之类的分页程序
显示命令菜单:利用脚本
检查客户端的原始程序:command="/bin/echo you tried to invoke
$SSH_ORIGINAL_COMMAND" ...key... $SSH_ORIGINAL_COMMAND环境变量保存着
客户连接时运行的原始命令。
限制客户端的原始命令,创建一个脚本,该脚本根据$SSH_ORIGINAL_COMMAND内容选
择不同的操作。
把客户端的原始命令记录在日志中:也是根据$SSH_ORIGINAL_COMMAND变量来做的一
个脚本。脚本内容如一:
#!/bin/sh
if [ -n "$SSH_ORIGINAL_COMMAND" ]
then
echo "`/bin/date`: $SSH_ORIGINAL_COMMAND" >> $HOME/ssh-command-log
exec $SSH_ORIGINAL_COMMAND
fi
3、限制来自特定主机的连接。由from选项完成。from="client.example.com" ...key...。强制
连接必须来自client.example.com。否则断开。from="!client.example.com" ...key...表示拒绝该
地址的连接。支持通配符。SSH2不支持该功能。但可以通过$SSH2_CLIENT变量提取客户
ip,编写强制命令脚本达到同样效果。
4、为远程程序设置环境变量。environment="EDITOR=emacs" ...key...,为每个连接修改默认的
环境变量。
5、设置空闲超时时间,这样如果客户端用户不再发送数据就强制将其断开。idle-timeout=5m,
该选项会覆盖服务器范围配置。
6、对到达的SSH连接禁用某些特性,例如端口转发和tty分配。禁用tty分配会使客户端没
有交互会话的能力。$SSH_TTY变量可显示tty情况。
用户的rc文件
ssh服务器会在每个连接到达时调用shell脚本/etc/sshrc,用户可把一些登录后想运行的脚本
写到这个文件中。用户可以在自已的目录下定义类似的脚本,如果有自定义的~/.ssh/rc则
/etc/sshrc则不会执行。
第九章 端口转发与X转发
使用SSH对其它应用程序在别的TCP端口上建立的TCP/IP传输进行加密和解密,这一过
程称为端口转发,其绝大多数操作都是透明的,功能非常强大。TELNET,SMTP,NNTP,IMAP
和一些基于TCP的不安全协议都可变得安全,只要将其连接通过SSH转发即可。端口转发
有时又叫做隧道传输。
例子:一个运行IMAP的服务器S,在家里的主机H上运行一个email程序,现在想用ssh
保护IMAP连接。
$ ssh -L2001:localhost:143 S
-L 表明是本地转发,,上面这命令可完成登录到S的功能,现在的这个SSH会话同时将H
的2001端口转发到S的143端口,在退出会话之前一直有效。并告知email程序使用被转
发的端口,通常邮件程序连接服务器的143端口,即套接字 (S,143)。现在要令其连接
本地主机H自已的2001端口,也就是套接字(localhost,2001)。创建本地转发时可以不用-L
选项,而在客户端配置文件中用LocalForward关键字。
LocalForward 2001 localhost:143 ssh1 openssh
LocalForward "2001:localhost:143" ssh2
-g 选项和GatewayPorts yes/no关键字可以配置除本地主机外的机器是否能使用本地的端口
转发功能。出于安全问题,该禁止这个功能。
远程转发端口与本地转发几乎完全相同,只是方向相反。此时服务器在本地,转发连接由远
程主机发起。假设你已登录进服务器S。则
$ ssh -R2001:localhost:143 H
-R代表远程转发。命令执行后,一条从远程主机H的2001端口到服务器S的143端口的安
全隧道就建立起来了。H上的任何程序都可以通过连接(localhost,2001)来使用此安全隧道。
而在客户端配置文件中用RemoteForward关键字.
RemoteForward 2001 S:143 ssh openssh
RemoteForward "2001:S:143" ssh2
$ ssh -o ClearAllForwardings=yes server.example.com 阻止第二条命令建立隧道
本地转发与远程转发
在本地转发中,应用程序客户端与监听端同SSH客户端在一起,应用程序服务器与连接端
同SSH服务器在一起。
在远程转发中,应用程序客户端与监听端同SSH服务器在一起,应用程序服务器与连接端
同SSH客户端在一起。
无远程登录的端口转发,连接时带-f参数。一次性转发用-fo,ssh1与openssh不支持这个功
能,但可用以下语句实现:
$ ssh -f -L2001:localhost:143 server sleep 10
终止
如果一个SSH会话现在还在活动当中,终止会出错。在SSH2中,如果退出有活动转发连
接的会话,该会话会依然打开,但会转到后台运行。直到转发连接终止。ssh1 and openssh
与此相反,如果要断开还在活动的会话,会出现警告,仍然在前台运行。
TIME_WAIT问题。在某些情况下,TCP连接断连时,其一端的套接字在很短一段时间内变
得不可用,所以在断连过程结束前不能把该端口用于TCP转发。
第十章 推荐配置
服务器范围配置
1、禁用其它访问方式。
关掉r-命令,方法如下:删除/etc/hosts.equiv文件,或改为只读空文件。禁用rshd,rlogind and
rexecd,通过修改inetd.conf文件。
2、/etc/sshd_config配置
HostKey /etc/ssh_host_key
PidFile /etc/sshd.pid
RandomSeed /etc/ssh_random_seed
StrictModes yes 要求用户保护其与SSH有关的文件及目录
Umask 0077 保证所有SSHD1创建是文件和目录都只能由其所有者(SSHD 运行的
UID)读取
port 22
ListenAddress 0.0.0.0
IdleTimeout 15m 15分钟空闲超时
KeepAlive yes 客户机死机时连接将会终止,而不会长期挂起。
LoginGraceTime 30 登录时成功认证的时限为30秒。
ServerKeyBits 768 服务器密钥长度
KeyRegenerationInterval 3600 服务器密钥一小时重新生成一次
PasswordAuthentication no 禁用密码认证
RhostsAuthentication no 禁用可信主机认证
RhostsRSAAuthentication no 禁用增强可信主机认证
RSAAuthentication yes 启用公钥认证
IgnoreRhosts yes 完全禁止SSHD使用.rhosts文件
IgnoreRootRhosts yes
UseLogin no 禁用UseLogin,防止万一使用了其它登录程序
AllowHosts xxx 根据需要设置
SilentDeny yes 任何被DenyHosts拒绝的连接都不会向用户返回消息,不必告诉攻击
者发生了什么,可以增加了排错的难度。
PermitRootLogin nopwd 允许超级用户通过SSH连接,但不能用密码认证
FascistLogging no 禁用FascistLogging日志方式,因为它会在日志中记录用户特定信息,对
攻击者有用。
QuietMode no 禁用QuietMode日志方式,使用日志更详细,敏感度更低
AllowTcpForwarding yes 允许tcp端口转发和X转发,保护其它的tcp连接
X11Forwarding yes
3、/etc/ssh2/sshd2_config配置
HostKeyFile /etc/ssh2/hostkey
PublicHostKeyFile /etc/ssh2/hostkey.pub
RandmoSeedFile /etc/ssh2/random_seed
UserConfigDirectory
IdentityFile
AuthorizstionFile
StrictModes yes
port 22
listenAddress 0.0.0.0
KeepAlive yes
RequireReverseMapping no
LoginGraceTime 30
由于sshd2没有设置服务器密钥的位数的关键字,用户得在启动时使用 -b 选项 $ sshd2 -b
1024 ....
AllowedAuthentications publickey
RequiredAuthentications publickey
IgnoreRhosts yes
UserKnownHosts no 禁用该项可防止用户给未知主机提供信任权限。
PermitRootLogin nopwd
Ciphers any 不能选none
QuietMode no
VerboseMode yes
Ssh1Compatibility no 禁用SSH-1兼容模式
#Ssh1Path /usr/local/ssh1/sshd1 出于实用原因,也可以启用此模式,之前要指明ssh1服
务器可执行文件位置
4、每账号配置
对于SSH1 AND OPENSSH,~/.ssh/authorized_keys中的每一个密钥都必须用适当的选项进
行限制,from选项限制只能从特定的主机访问特定的密钥。例如,假设文件中包含你家那
台pc(myhome.isp.net)的公钥,而其它机器根本不可能用那个密钥来认证,我们就可以明确
限定这一关系:from = "myhome.isp.net" ...key...。还要对适当的密钥设置空闲超时时间:from
= "myhome.isp.net" ,idle-timeout=5m ...key...。
最后,考虑每一个密钥是否需要对到达的连接使用端口转发,代理转发以及分配tty等,如
果不需要,就可以分别用no-port-forwarding,no-agent-forwarding and no-pty禁用这些特性。
5、密钥管理
至少创建1024位长的用户密钥,并用好的口令对密钥进行保护。
6、客户端配置
离开正在运行的ssh客户端时,一定要用密码保护。
在客户端配置文件中启用某些安全功能,并将其设置为最强
Host *
FallBackToRsh no 禁止使用不安全的r-命令(ssh2)没有这个问题。
UseRsh no
GatewayPorts no 禁止远程客户端连接本地的转发端口
StrictHostKeyChecking ask 在主机密钥发生变化时提醒你。请求你的处理意见。
配置“/etc/ssh/ssh_config”文件
“/etc/ssh/ssh_config”文件是OpenSSH系统范围的配置文件,允许你通过设置不同的选项
来改变客户端程序的运行方式。这个文件的每一行包含“关键词-值”的匹配,其中“关键
词”是忽略大小写的。下面列出来的是最重要的关键词,用man命令查看帮助页(ssh (1))
可以得到详细的列表。
编辑“ssh_config”文件(vi /etc/ssh/ssh_config),添加或改变下面的参数:
# Site-wide defaults for various options
Host *
ForwardAgent no
ForwardX11 no
RhostsAuthentication no
RhostsRSAAuthentication no
RSAAuthentication yes
PasswordAuthentication yes
FallBackToRsh no
UseRsh no
BatchMode no
CheckHostIP yes
StrictHostKeyChecking no
IdentityFile ~/.ssh/identity
Port 22
Cipher blowfish
EscapeChar ~
下面逐行说明上面的选项设置:
Host *
选项“Host”只对能够匹配后面字串的计算机有效。“*”表示所有的计算机。
ForwardAgent no
“ForwardAgent”设置连接是否经过验证代理(如果存在)转发给远程计算机。
ForwardX11 no
“ForwardX11”设置X11连接是否被自动重定向到安全的通道和显示集(DISPLAY set)。
RhostsAuthentication no
“RhostsAuthentication”设置是否使用基于rhosts的安全验证。
RhostsRSAAuthentication no
“RhostsRSAAuthentication”设置是否使用用RSA算法的基于rhosts的安全验证。
RSAAuthentication yes
“RSAAuthentication”设置是否使用RSA算法进行安全验证。
PasswordAuthentication yes
“PasswordAuthentication”设置是否使用口令验证。
FallBackToRsh no
“FallBackToRsh”设置如果用ssh连接出现错误是否自动使用rsh。
UseRsh no
“UseRsh”设置是否在这台计算机上使用“rlogin/rsh”。
BatchMode no
“BatchMode”如果设为“yes”,passphrase/password(交互式输入口令)的提示将被禁止。
当不能交互式输入口令的时候,这个选项对脚本文件和批处理任务十分有用。
CheckHostIP yes
“CheckHostIP”设置ssh是否查看连接到服务器的主机的IP地址以防止DNS欺骗。建议设
置为“yes”。
StrictHostKeyChecking no
“StrictHostKeyChecking”如果设置成“yes”,ssh就不会自动把计算机的密匙加入
“$HOME/.ssh/known_hosts”文件,并且一旦计算机的密匙发生了变化,就拒绝连接。
IdentityFile ~/.ssh/identity
“IdentityFile”设置从哪个文件读取用户的RSA安全验证标识。
Port 22
“Port”设置连接到远程主机的端口。
Cipher blowfish
“Cipher”设置加密用的密码。
EscapeChar ~
“EscapeChar”设置escape字符。
配置“/etc/ssh/sshd_config”文件
“/etc/ssh/sshd_config”是OpenSSH的配置文件,允许设置选项改变这个daemon的运行。
这个文件的每一行包含“关键词-值”的匹配,其中“关键词”是忽略大小写的。下面列出
来的是最重要的关键词,用man命令查看帮助页(sshd (8))可以得到详细的列表。
编辑“sshd_config”文件(vi /etc/ssh/sshd_config),加入或改变下面的参数:
# This is ssh server systemwide configuration file.
Port 22
ListenAddress 192.168.1.1
HostKey /etc/ssh/ssh_host_key
ServerKeyBits 1024
LoginGraceTime 600
KeyRegenerationInterval 3600
PermitRootLogin no
IgnoreRhosts yes
IgnoreUserKnownHosts yes
StrictModes yes
X11Forwarding no
PrintMotd yes
SyslogFacility AUTH
LogLevel INFO
RhostsAuthentication no
RhostsRSAAuthentication no
RSAAuthentication yes
PasswordAuthentication yes
PermitEmptyPasswords no
AllowUsers admin
下面逐行说明上面的选项设置:
Port 22
“Port”设置sshd监听的端口号。
ListenAddress 192.168.1.1
“ListenAddress”设置sshd服务器绑定的IP地址。
HostKey /etc/ssh/ssh_host_key
“HostKey”设置包含计算机私人密匙的文件。
ServerKeyBits 1024
“ServerKeyBits”定义服务器密匙的位数。
LoginGraceTime 600
“LoginGraceTime”设置如果用户不能成功登录,在切断连接之前服务器需要等待的时间(以
秒为单位)。
KeyRegenerationInterval 3600
“KeyRegenerationInterval”设置在多少秒之后自动重新生成服务器的密匙(如果使用密匙)。
重新生成密匙是为了防止用盗用的密匙解密被截获的信息。
PermitRootLogin no
“PermitRootLogin”设置root能不能用ssh登录。这个选项一定不要设成“yes”。
IgnoreRhosts yes
“IgnoreRhosts”设置验证的时候是否使用“rhosts”和“shosts”文件。
IgnoreUserKnownHosts yes
“IgnoreUserKnownHosts”设置ssh daemon是否在进行RhostsRSAAuthentication安全验证
的时候忽略用户的“$HOME/.ssh/known_hosts”
StrictModes yes
“StrictModes”设置ssh在接收登录请求之前是否检查用户家目录和rhosts文件的权限和所
有权。这通常是必要的,因为新手经常会把自己的目录和文件设成任何人都有写权限。
X11Forwarding no
“X11Forwarding”设置是否允许X11转发。
PrintMotd yes
“PrintMotd”设置sshd是否在用户登录的时候显示“/etc/motd”中的信息。
SyslogFacility AUTH
“SyslogFacility”设置在记录来自sshd的消息的时候,是否给出“facility code”。
LogLevel INFO
“LogLevel”设置记录sshd日志消息的层次。INFO是一个好的选择。查看sshd的man帮
助页,已获取更多的信息。
RhostsAuthentication no
“RhostsAuthentication”设置只用rhosts或“/etc/hosts.equiv”进行安全验证是否已经足够了。
RhostsRSAAuthentication no
“RhostsRSA”设置是否允许用rhosts或“/etc/hosts.equiv”加上RSA进行安全验证。
RSAAuthentication yes
“RSAAuthentication”设置是否允许只有RSA安全验证。
PasswordAuthentication yes
“PasswordAuthentication”设置是否允许口令验证。
PermitEmptyPasswords no
“PermitEmptyPasswords”设置是否允许用口令为空的帐号登录。
AllowUsers admin
“AllowUsers”的后面可以跟着任意的数量的用户名的匹配串(patterns)或user@host这样
的匹配串,这些字符串用空格隔开。主机名可以是DNS名或IP地址。
2005年10月02日 星期日
如何实现自动登录Linux(转载)
开机自动登录linux,并自动运行X window应用程序,有其特殊的应用背景,如基于linux平台的监控系统,linux启动后不需要身份验证,而直接运行监控程序等等。本文以Redhat7.2为平台,结合linux启动过程,介绍了如何避免身份验证自动登录,并直接进入X window自动运行应用程序。
linux 在启动过程的最后阶段(具体启动步骤略),init 会根据 /etc/inittab文件的最后一行x:5:respawn:/etc/X11/prefdm -nodaemon运行/etc/X11/prefdm脚本,(Red hat 7.2缺省时是这样的)。prefdm脚本的主要任务是完成X window的启动,可以有几种启动X window的方法,都包含在prefdm脚本中,几种主要方法有:
- 运行xdm启动X window;
- 运行gdm,进入gnome桌面环境;
- 运行kdm进入kde桌面环境;
- 自动登录进入linux;
prefdm脚本框架大致如下:
|
在/etc/X11/prefdm脚本中,是否实现自动登录有一个条件测试开关,事实上,可以在这里注释掉测试开关,直接执行启动X window的操作。
自动登录实质上就是绕过身份验证,直接启动X window。X window的启动可以由xinit来完成。
- Xinit用来启动X window系统服务器以及系统上的第一个客户程序,可以通过为xinit传递命令行参数的形式指定要启动的服务器及客户程序。如果不传递参数给xinit,它将在用户的根目录下寻找并运行 .xinitrc脚本来启动客户程序;在用户的根目录下寻找并运行 .xserverrc脚本来启动服务器。如果xinit在用户的根目录下找不到.xinitrc、.xserverrc,xinit将使用缺省的X :0。
- 实际上,用startx来启动X更为方便。对于运行单一会话的X window 系统,startx提供了更为良好的用户接口。同样,startx首先在用户的根目录下寻找 .xinitrc及.xserverrc脚本,如果找不到这两个脚本,startx将使用/etc/X11/xinit/xinitrc以及/etc/X11/xinit/xserverrc脚本。
startx脚本的最基本框架是:
-
a、 寻找.xinitrc,如果没有则使用xinitrc;
b、 寻找.xserverrc,如果没有则使用xserverrc;
c、 根据找到的脚本确定xinit的参数;
由此可看出,startx在不需要传递任何参数的情况下,可以完成启动X的任务,因此,可以如下修改/etc/X11/prefdm脚本来实现自动登录:
|
当然,应确保/etc/inittab中的启动级别为5。
重新启动系统,会发现系统不验证用户身份,直接进入X window,此时的用户身份为root。但是,如果原来root有自己的桌面、默认shell时,上述方法启动X不一定保证还能拥有原来的设置。为了在启动X后,在避免验证身份的同时,又不改变用户原来的设置,那么在运行startx之前,还有工作要做。
三、自动登录后,保持用户原来的配置(桌面、shell以及其它的一些环境变量)。
观察原来/etc/X11/prefdm脚本的自动登录部分:
|
不难看出,脚本中保留了自动登录的接口:一个可执行文件/usr/sbin/autologin以及一个配置文件/etc/sysconfig/autologin。
1、/etc/sysconfig/autologin配置文件的实现:
|
2、/usr/sbin/autologin可执行文件的实现:
|
运行gcc -o autologin autologin.c,拷贝autologin可执行文件到/usr/sbin/autologin,拷贝autologin配置文件到/etc/sysconfig/autologin。 重新启动系统,会直接进入X window并保留用户原来所有的风格。
如果不需要自动登录的配置文件/etc/sysconfig/autologin,所有的操作都在/usr/sbin/autologin以默认的方式实现(比如,默认登录身份为root,默认执行操作为/usr/X11R6/bin/startx等),那么,/etc/X11/prefdm脚本的自动登录部分可简化如下:
|
即在脚本中去掉条件测试开关,直接执行/usr/sbin/autologin,这时,只需要拷贝autologin可执行文件到/usr/sbin/autologin,不再需要拷贝autologin配置文件到/etc/sysconfig/autologin。
四、选择进入kde或者gnome,并自动启动X window应用程序
- 如果重新启动后系统进入了kde,而用户需要进入gnome,只需运行switchdesk gnome在重新启动系统即可,以后每次启动时会自动进入gnome;反之亦然。
- 一般系统自动登录的目的是启动X window 后自动运行某个X window程序。如果系统默认的启动级别为3,那么如果要在系统启动后自动运行某些应用程序,只需要在某些脚本中加入相应命令即可,不再详述。在X window启动后自动运行应用程序要复杂一些,幸好,kde和gnome都为此留下了自动启动接口。如果在kde桌面环境下自动启动应用程序,只需要把应用程序名字加入/root/.kde/Autostart/目录下即可(这里注意不同用户的根目录可能不同,如用户zyx的根目录可能为/home/zyx)。如果在gnome桌面环境下自动启动应用程序,只需把应用程序的名字加入/主菜单/程序/设置/会话/会话特性及启动程序的startup programs属性页中即可。
2005年09月29日 星期四
完全使用Linux工作(转载)
我已经半年没有使用 Windows 的方式工作了。Linux 高效的完成了我所有的工作。
GNU/Linux 不是每个人都想用的。如果你只需要处理一般的事务,打游戏,那么你不需要了解下面这些了。
我不是一个狂热的自由软件份子,虽然我很喜欢自由软件。这篇文章也不是用来推行自由软件运动的,虽然我觉得自由软件运动是非常好的。
这篇文章也不是用来比较 Linux 和 Windows 内核效率,文件系统,网络服务的。我现在是作为一个用户而不是一个开发者来说话的,我们的讨论是基于操作,应用层面的。是为了告诉大学里还不了解,或者不理解 UNIX 的科学工作者和大学生,UNIX 比 Windows 更适合用于科学研究工作,请大家理解 UNIX 的工作方式,不要用 Windows 的标准来要求 Linux,而要用一个科学工作者的标准来要求自己,用UNIX 的思想来武装自己。
我显然是反对在大学,特别是理工科专业推广 Windows 的。我也反对在对"娃娃"们的计算机启蒙教育中使用 Windows。因为 Windows 不论从技术上,经济上,思想风格上都是与我们培养高科技人才的目标格格不入的。Windows 的流行属于历史遗留问题,爷爷一级的人当然已经不可救药,但是我们不应该让下一代继续走上歧途。
UNIX 不是计算机专家的专利
当我建议一些非计算机专业的人用 Linux 的时候,很多人说:"UNIX 是计算机系的人用的,我们不能理解。" "UNIX 是男孩用的,我们女孩不用。"
但是其实世界上的大多数科学家和工程师几乎用的都是 UNIX 作为他们的电脑工具。就因为它简单,可靠,稳定,强大,有趣。甚至很多时候 UNIX 就是唯一的选择。
你说:"我们都会用 UNIX 的话,你们计算机专业的人还用来干什么?" 很容幸的告诉你,计算机专业的有一部分人就是专门为你们提供这样强大而方便的计算机工具的。如果他们制造的工具只有自己会用的话,那这个工具还有什么用?
理解 GNU/Linux 不要用 Windows 的标准来要求 Linux。
由于GNU/Linux这个词太长,下面如果没有特别指明,"Linux"就是指GNU/Linux"。
在这个年代,恐怕没有人需要我来介绍 Linux 是什么了吧?如果你觉得"Linux 只不过是跟 DOS 差不多的东西",那请问问你旁边的 Linux 用户,Linux 到底是什么?
那为什么我还要写一篇这样的文章?因为,我发现还有很多人不不理解 Linux 和 UNIX,虽然他们也在用它,但是他们有时会问:"为什么 Linux 不能像 Windows 那样 ……?","怎么Redhat Linux不能 mount NTFS 分区!","Linux 下用什么整理硬盘?","什么时候OpenOffice才能完全兼容Word文件啊?","现在还有什么Windows能干的事情Linux干不了的?"……
他们有40G的硬盘,却只为 Linux 分配了2G空间,有时还抱怨"这个东西怎么占这么多硬盘!" 似乎 Windows 该占用大部分硬盘。他们把重要的数据装在Windows的分区,似乎信不过Linux。他们总是到处寻找新奇的,好看的GUI程序,对命令行的东西一概不屑一顾。他们对Drag&Drop,菜单配置,自动升级非常感兴趣。他们如果找到一个很像 Windows 程序的 Linux 程序,一定会很高兴的说:"哈哈!Linux 也能……了!"如果Linux在某种测试中胜过Windows,他们会高兴得跳起来。他们没有办法用Linux 解决问题的时候,甚至用Wine来运行Windows程序。有时实在没办法,只好重起到Windows,或者干脆省得麻烦,在 Windows 下装一个 VMWare 虚拟一个 Linux 玩。
你如果出现了上面的情况,说明你的思想受到了 Windows 的某种潜移默化的影响和误导。你没有能够从本质上理解存在于 Linux 身上的 UNIX 思想。你支持 Linux,你喜欢 Linux,你能从中感觉到快乐,这非常好。你现在只需要明白的是:Linux 从来就不是一个玩具,它是天才UNIX的后代。UNIX 是自晶体管发明以来最伟大的发明,它从诞生那一天开始就比 Windows 的设计出色。
你要体会什么叫做"设计",一个糟糕的设计并不是到后来缝缝补补就可以变好的,而一个出色的设计,不但可以以不变应万变,而且可以影响到后来者。一个出色的设计配上一个出色的实现,那就是非常出色的发明。Linux 就是这样的一个出色的发明。Linux 并不需要追赶 Windows,也不需要打垮微软。它的最终目标是改变整个计算机世界,还人们自由,给人们乐趣和方便。
Unix 是简单的,你不需要成为一个天才也能理解这种简单。
UNIX的设计者 Dennis Ritchie 说:"Unix is simple. It just takes a genius to understand its simplicity." 但是我不这么认为,因为我不是一个天才,但是我却勇敢的把 Windows 完全删除掉,遇到不明白的事情的时候努力用 UNIX 的方式去解决,而不是寻求 Windows 的帮助。现在我体会到了 UNIX 的思想和好处,我可以用比 Windows 高效几倍的效率工作。因为我相信这样的信念:"Windows 能办到的事 Linux 一定能办到,而且办的更好。"
这小节开头的话应该改成:"Unix 是简单的,你不需要成为一个天才或是计算机专家。但是在这个冲斥着 Windows 错误观念的世界,你需要信念和勇气才能理解它的简单。" 我下面就告诉你一些我理解到的东西。首先,你要知道的是微软在国际科学领域是根本没有地位的。
微软的地位
微软的名声在欧洲和美国的大学里,特别是在计算机系里之坏,大家可能有所耳闻。我认识的 MIT,Stanford 的教授,贝尔实验室的专家,甚至一个欧洲小国的高中计算机老师都绝口不提微软的名字。在他们眼里,微软只是一个没有真技术,专靠在落后国家商业宣传和垄断经营的小公司。这个"小"并不是说它人少,钱少,而是说它先进技术少。
我上次和王益合作写了一个算法演示程序,那个算法是贝尔实验室一位科学家Steven Fortune很天才的发明,为了程序能够被身边大多数人使用,我们选择了 VC+MFC 作为平台。我在分析算法时还得到 Fortune 很热情的鼓励,寄给我一份资料,还多次回信耐心的给我讲解了很多细节。但是程序完成之后,我把样品发给 Fortune,他回信说:"对不起。我机器上没有 MFC。" 话说的很客气,但是我已经感觉到了他对 Windows的不屑。然后我把 MFC 静态编译进程序再发给他,他就没有再回信了。他显然不是瞧不起我,而是确实有难处。
你能感觉到这位科学家对微软和 Windows 是什么态度了吧?不是反感,而是他心里根本没有 Windows 这个东西!微软在高科技领域没有发展,那么它怎么生存呢?到发展中国家去发展一下,他们的人民还对电脑一无所知,我说不定甚至可以打入大学的计算机系呢。我送他们软件,我捐钱盖大楼,我出钱找图灵奖获得者来演讲,让他们觉得我们都是科学家!
好了,现在全国的大学包括清华,几乎所有人机器必装盗版 Win2000,Office XP,学校的选课系统是非IE不能正确浏览,论文用 Word 编辑,演示用ppt做,email 的通知附件是 doc 文件,你不用 Word 打不开,连 863 项目都用 VC 写程序了。我很久以前就看到一份报纸说,"微软为什么不严厉打击盗版?" 这篇文章说,微软非但不打击中国的盗版行为,而且有放任之趋势。放长线吊大鱼,"以后我要你们加倍的来还我!" 确实如此,它的目的快实现了。
Windows 笼罩下的中国计算机教育
说句丢脸的话,比尔盖茨很久以前是我的偶像…… //blush
在中国,比尔盖茨被很多人奉为神圣,"少年电脑天才",甚至有的人提到他的名字就做出"抱拳对天"的姿势。很多人谈到微软的"新技术","高科技" 都是眉飞色舞。各种"VC编程圣经","深入了解 Visual C++"之类的书,在开头几页都会出现非常肉麻的字眼,"在那团团的混沌中,一个开天辟地的精灵,Windows 1.0,诞生了……"
微软的软件被这么多人盗用,那么人们是怎样使用这些盗版程序的呢?先看看电脑培训班,教的都是一些 DOS 命令,打字,Windows 基本操作,Word 文档处理,PowerPoint,高级班可能有 Excel,Access…… 参加各种微软认证考试,MCSE,MSDE 的人络绎不绝。考试辅导班都贴出了"280元,考过为止"之类的字样。考试参考资料更是昂贵,有些电脑书店整整两书架都是"Microsoft Press"的东西。我有个同学参加认证考试,每门考试都要200多元。而且你一次考不过可以再考,又要交钱。他后来还津津乐道跟我说,看我,花了XXXX(一个四位数)元考过了微软认证,得到一张比尔盖茨亲笔签名的证书和价值6000元的 Windows XP 内部发行版。
"电脑要从娃娃抓起",我们再来看看娃娃们学的是什么。大部分家长给孩子买了电脑之后,他们首先就会装一个盗版的 Windows,然后买来盗版的游戏开始玩。如果哪个孩子会用 Delphi 编程序,那可不得了。报社记者,电视台争相报导,说,某某学校的初中生某某,在别人都还在玩电脑游戏这种"初级阶段"的时候就已经用 Delphi 写程序了。镜头还瞄准了他显示器上面的像框中的比尔盖茨头像!
我刚进入大学计算机系时还不懂得什么是操作系统,因为我以前只用过"中华学习机"。看到新入学的同学们各个谈论的都是 "Windows 95","VC"…… 我简直觉得我落后了好几十年一样,整个一土人,根本跟他们答不上话。好不容易找到一个比较熟的同学问了一下:"你们天天谈论的瘟95是什么啊?"答:"win95就是一个操作系统,跟DOS是一类。""朵死是什么?" "你连DOS都不知道是什么?别在计算机系混了。" 学校上课当然不讲VC编程之类的东西,但是上 Pascal 的老师有一次就说:"嗨,我们学校真是落后。现在别人都用 C, C++,甚至 VC 了,我们还在讲 Pascal。不知道什么时候才能有VC课啊。你们出去也是要用VC的,只好自学了。" 于是,有些同学很多时候上课都捧着一本很重的"Windows 编程大全"之类的书,根本没有听课。吃饭时就念念有词的跟我说,"代码的优化是无止境的","匈牙利命名法真是伟大的发明" …… 这就是中国很多大学计算机系的情况。
感觉到无知了?这不是偶然的,而是微软长久以来埋下的伏笔。它要让无知的大家都把它奉为神圣,它要让支持UNIX,Xwindow的人一旦说 UNIX 好,Xwindow 好的时候,都被一群人围着说教:"这个 Windows 也能做到","你对 Windows 有偏见","微软才是主流啊","你敢瞧不起 win2k?",".NET 就是世界潮流","微软的毕竟是新技术","有钱就是有技术"…… 甚至在一番论战比较后败下来还是要说:"Windows 性能差点,但是易用性强","Windows 是老百姓用的,要求别那么?quot;,"微软那么有钱,以后想超过 UNIX 还不容易吗?"……
发达国家的计算机教育
我前段时间在 USENET 发文问有关 Scheme 语言的问题时,认识了一位丹麦人。他解决了我所有的问题,并且建议我阅读一些很"深奥"的有关程序语言语法,文法的书,他告诉我很多网站可以学习 LISP,Scheme,人工智能,算法。他叫我看 Jonathan Rees 的论文 "Syntactic Closures"。他还打包给我寄过来一份 MIT 的 "How to Design Programs"。他说他在自己的 PC 机上装的是 Linux,他用 Emacs 编辑,运行Scheme 程序。他对 Emacs 的了解和爱好真是使人惊讶。他大学本科毕业时做的毕业设计是一个 Scheme 解释器。这对于我来说是望尘末及了。
他是那么的不厌其烦,我的每一个问题他都详细的回答。我有时都觉得过于详细了,怎么这么耐心啊?我觉得他似乎是我的高中老师。他是什么样的人呢?我好奇的打听了他的情况。原来,他是丹麦一所普通高中的计算机老师。
他说他在高中里讲授程序设计和算法,计算机语言文法。他说用 Scheme,他的学生不用再为内存泄漏等程序语言本身的问题而烦恼,而专注于问题和算法本身。有利于培养学生解决问题的能力,特别是用计算机解决数学问题的能力。
天哪!为什么欧洲出现那么多数学家,几何学家?你看看别人重视的是什么!我们的计算机教育如果继续这样下去,只会沿着弯路越走越远!
微软和它的朋友们的如意算盘
下面来看看微软的收入是怎么来的。首先,Windows 98系列操作系统,一个就是 100多美元,每次升级又是几乎同样的价钱。Windows NT 还要贵几倍,而且有用户数目限制,5个用户的,10个用户的…… 以后如果要增加用户数目还要按比例付钱。
花了如此多钱买来的操作系统就能用了吗?它竟然连压缩程序都没有提供!你装上Windows 之后一般第一件事就是去下载一个 WinZip 吧,"只要 29 美元"。Windows会中病毒啊,马上花 70 美元买一个 Norton AntiVirus 吧。还有黑客呢?再买一个Norton Internet Security 好了,100 美元。系统需要优化,磁盘需要整理,买一个Norton System Works 是你最佳的解决方案,100美元。
可是你现在还是不能干正事啊!你想要一个 Word, PowerPoint?那就买一套 Office XP 吧,一起买便宜些,$459.90。
那些程序不会用啊!那些菜单怎么设置,到底有什么功能啊?看"帮助"也学不会。买本书看看吧,我推荐"Special Edition Using Microsoft Office XP",不贵,$27.99。这本书里面大部分是屏幕抓图,还是买一本旧的比较划算,$17.85。
你如果只是当个秘书,上面的差不多还凑合了。可是你有更高的追求,你想成为 Windows程序员。首先买一个 Visual Studio.NET 吧,要不然怎么编译程序。$494.95。
为了紧跟微软动向,世界潮流,不能不注册个 MSDN 什么的吧?这个贵一点,不过物有所值啊,$2,799。
嗯,你现在已经是上层阶级,白领人士了。你现在可以像这样"自由"的,"安全"的生活了。
为什么要反对使用 Windows
很多人都说不应该完全否定 Window,Windows 也有它的长处。不应该骂微软。
对。Windows 容易操作,适合普通用户。如果微软把它自己定位在 P&G,Philips 那样的地位,能够给我们的百姓提供周到的,完善的,价廉物美的服务。那我肯定是很喜欢它的。但是从上面的种种情况说明,微软是一个野心极大的国际垄断组织!它的产品没有一个是不出问题的:Windows 不稳定,容易中病毒,而微软不为大家免费提供杀毒软件。我就是要让你们花钱买我的朋友 Symantec 的杀毒软件,谁叫你们已经上了我的贼船?这叫什么售后服务啊!
你买来微软的程序,安装的时候一般都有一个协议,说:"由于微软的程序造成你的数据损坏或丢失,微软概不负责。" 我想很多人肯定觉得这个不合理,不想按那个 "I accept"。但是你的软件买都买来了,钱都花了,现在一按 "I decline",安装程序马上就会退出。你只好被迫点击了 "I accept"!这不是不平等条约吗?
我已经目睹了好几个朋友的文档被 Microsoft Word 损坏,有的是编辑了十多天的30多页的论文,有的是费了很大工夫做出来的个人简历,那个朋友为此失去了到自己向往的P&G 工作的机会。就在他要投简历的前一个晚上,就在那一瞬间…… 不知道他痛哭的时候有没有想起要投诉微软,可是谁叫我们用的都是盗版呢,况且你还点击了 "I accept"。
微软仗势已经占有大部分PC市场,制定不符合国际标准的"微软的标准",以不合理的方式压制其它公司的软件,这个问题已经在美国司法部闹了很久了。他甚至在 Windows系列操作系统中放置能够通过网络泄漏用户信息的代码,以至于 Windows 刚进入澳大利亚时被澳大利亚政府禁止使用。
有些人说:"微软毕竟开创了一个历史,造就了今天的 IT 行业。" 但是,如果没有微软,我们今天早就用上非常稳定,非常可靠,非常方便,非常"傻瓜"的软件了!微软是阻挡信息技术发展的罪魁祸首。
微软的程序的工作方式(注意,我只是说操作方式,病毒的事情另外算)确实适合于一般家庭,上上网,发发邮件,打打游戏都不错。可是微软却要把自己包装成什么"高科技"企业,要在世界各地设置"研究院",在大学计算机系赠送不适合用于科研的 Windows产品,甚至出钱请图灵奖得主来中国畅谈"二十一世纪的计算",还在大会上宣传自己的 .NET 技术。非要把别人认为自己是科学的,自己是领导世界高科技的。但是呢?它什么高科技也没有。欧洲,美国,哪一个关键部门在用微软的东西?NASA? DOE? CERN?你仔细想一想,微软的程序对人类到底有什么重大作用?
什么是 Windows 能干而 Linux 干不了的事情?---
"Windows 能干而 Linux 干不了的事情,那就是不需要干的事情。"
有个朋友看我半年没有用 Windows,有时就会问我:"你只用 Linux,有没有发现有些Windows 能处理的事情 Linux 干不了?"---
我回答说:"Windows 能干而 Linux 干不了的事情,那就是不需要干的事情。"
Windows 能做的有益的事情 Linux 都能做---
Windows 下的某些功能确实是我们需要的,那么 Linux 的开发者们和用户也需要这种功能,他们就会去实现这种功能,而且比 Windows 的方式好得多。由于大多数科学家,工程师用的都是 Linux 或者某种商业 UNIX, 所以几乎所有商业的科学工程程序,比如Matlab, Mathematica, AutoCAD, Candence的,Synopsys的,Avant! 的……全都是先有UNIX 的版本(包括Linux),然后再考虑移植给 Windows,甚至根本不移植给Windows,因为 Windows 的机器一般没有足够的能力运行这样的程序。你不要以为只有 Windows 才有 PSpice, UNIX 的 HSpice 要好得多,而且可以运行在大型主机上。当然它们不是免费的,但是它们值那个价钱。
但是 Windows 下有些东西在 Linux 下没有很相似的,或者你找到很多类似的,但是它们每一个比起 Windows 的那个程序都要差很多,那么原因有两种可能性:
有一个完全类似的程序,但是由于它乍一看不漂亮,被你忽略了。而其它程序虽然看起来很漂亮,但是它们是一些初学编程的人写的。现在由于 Gtk, Qt 的诞生,Linux 下开发图形界面程序极其简单,很多初中生甚至小学生都可以随手编出一些漂亮不中用的程序。如果你整天寻找这样的程序挑来挑去,永远也找不到你满意的。当然也有一流的程序用 Gtk 和 Qt,比如 GVIM 就可以用 Gtk 作为图形界面,我还知道 Synopsys 一些程序用了 Qt。
我曾经也犯过这样的错误,从外表区分一切。结果优秀的 FVWM, lftp, Mutt, wget 都被我忽略过。当我找回它们的时候,我是那么的羞愧不已,它们现在都是我的朋友我第一次看到 FVWM 觉得它只不过是一个有很厚很难看边框的东西。可是现在,我的同学看到 FVWM 都说:"哇!真漂亮。"
有另一种完全不同的方式可以达到相同的目的,甚至更好。
很多人很关心 Open Office, Star Office, AbiWord, ... 他们多么盼望有一天某一个Linux 程序能够完全兼容的打开一个复杂的 doc 文档。但是你永远也不可能有那一天。为什么呢?因为微软为了占有市场,必定不会让其它系统的程序能够完全兼容它的文档格式。它一定会不断变化 doc 文档的内部结构,隐藏一些秘密,让其它公司的程序打开 doc 文档时总是有某种问题,从而你必需购买 Microsoft Office 和 Windows。
你应该想一下,那么多的高智商的大学教授,科学家,学生,他们用的都是 Linux 或者其它类型的 UNIX,他们没有 Word 可用,怎么处理文档呢?这么多年没有一个像Open Office 的程序出现,难道大家没有办法写文档吗?
显然不是这样。你看看那些高水平的学术杂志,论文,那些大学教授的网页,那些漂亮的幻灯片,它们是什么做的?原来 UNIX 用户早就有非常方便的 troff, LaTeX, SGML等东西可以处理文档,而且它们比起 Word 都要高明的多。Word 显然被这些大拿忽略了,以至于很久以来没有人想在 Linux 下开发一个类似 Word 的程序,除非某些公司想抢微软的饭碗。
很多人留着 Windows 在硬盘上的原因无非是为了用 Word 和 PowerPoint。我见过一个教授,他的 Windows 笔记本电脑上除了 PowerPoint 什么都没有。有一天演示的时候,他指着堆乱字符说:"对不起,这是一个公式……怎么每次都是这样……" 其实有比PowerPoint 好几百倍的东西可以制造幻灯片,你可以用最简单的方法制造世界一流效果的论文和幻灯片。你待会儿可以看看我的TeX网页,你就会知道为什么我可以完全离开 Windows。
Windows 能做的那些没用的事情 Linux 永远做不好
电脑游戏
有些人说 Linux 下不能玩 Windows 下所能得到的所有游戏。的确,Linux 下虽然也有少量的游戏,比如 Quake。但是它没有 Counter Strike, 没有 Star Craft, ……
并不是说电脑游戏不该玩,但是应该适可而止。电脑是用来处理事务,帮助你学习,解决问题的工具,而不是一个玩具!整天沉迷于电脑游戏中,而不出去感觉外面的世界,你会变得越来越冷酷,越来越缺乏人情味。你与真实的世界越来越远。
你可以在 CS 里杀人,你可以在 Tomb Raider 里探险,你甚至可以在 Tony Hawk's Pro Skaters 里滑板…… 但是 It's not real!你虽然有很高的"反恐技巧",但是遇到歹徒的时候,你是那么的怯懦;你虽然控制 Laura 伸手敏捷,但是你打篮球的时候怎么总是被人断球?你虽然可以轻易的在 THPS 里作出一个 "360 kickflip to hangten grind to fakie",但是你踩在自己的滑板上的时候还不会 ollie!
说回来,如果你偶尔玩一下电脑游戏未尝不可。但是世界上有远比 Windows + PC 更好的游戏方式。Sony 的 PlayStation2, SEGA 的 DreamCast, Nintendo 的 N64,Namco的街机……每一个都比 Windows 游戏精彩,每一个都有如此高的3D性能,以至于Pentium4, Itanium + GForce4 都无法与它们比美!
Linux 的用户们都是关心解决世界的关键问题的份子,他们哪里有时间用自己的机器来玩游戏啊?他们每天用Linux高效的做完自己的工作就到阳光下享受自然去了。要玩游戏也是玩一些类似推箱子,贪吃蛇之类的智力小游戏。所以,你知道为什么 Linux 几乎没有游戏了吧?
"整理硬盘,优化系统"
这是一个非常有意思的话题,仅次于有关"病毒"的话题。相信很多 Windows 用户都有整理硬盘的经历。在很多 Windows 用户眼里,"硬盘用久了,会出现碎片,速度会减慢,需要一个程序来整理,整理硬盘的时候不要做其它工作",这好像是天经地义的事情。
我也曾经津津有味的看着 Norton Defrag 一点一点的把我的硬盘排序,调整,用图形的方式显示出来,然后报告?quot;100% 没有碎片。你的硬盘现在已经达到最佳状态。" 我现在才发觉我那时是多么的幼稚。
Linux 和 UNIX 用户似乎从来没有"整理硬盘"这种说法呢?你觉得很奇怪吗?如果你觉得很奇怪,那说明你的思想在某种程度上被微软的垃圾程序禁锢了。你需要明白,UNIX 的大型主机很多必须是一天24小时,一年365又1/4天不停运转的,要是每个星期都要整理一次硬盘,在整理的时候几乎不能干任何事情,那是绝对行不通的!
Linux 机器根本不用整理硬盘,这就是为什么没有看到过 Linux 用户整理硬盘。Linux 的文件系统是比 Windows 的 FAT, FAT32, NTFS 高明得多的文件系统,它们不但可以对文件设置权限,实施完全的保护,而且可以"越用越整齐","越用碎片越少"!你应该把文件大部分放在 Linux 的分区,而不是 Windows 分区,因为它比 Windows分区可靠得多。
还有更滑稽的事情就是有很多"Norton System Doctor","Windows 优化大师","超级兔仔注册表魔法" 之类的程序存在,而且价格昂贵。似乎一个操作系统本来应该有很多问题,需要别的厂商做程序来"优化"它,而且为了得到优化,你需要付钱!这些问题 Linux 根本就没有,所以不需要什么优化。Linux 内核本身就是高度优化的。
IDE
有些人在抱怨为什么 Linux 没有一个良好的 IDE 开发环境。Linux 现在已经有一些IDE 了,但是总是有很多问题。你是不是正在寻找,正在期望 Linux 某一天可以有一个VC那样的开发环境?你有没有发现你正在进入微软给你设下的怪圈?你为什么一定要用 IDE?你说:"IDE 开发迅速,调试方便,适合大型程序……" 那说明微软的程序在你脑子里已经比较根深蒂固,你需要好好清醒一下了,看看我来告诉你。
高明的 UNIX 程序员不用 IDE,IDE 从来就是给初级 Windows 程序员用的。
你看看大型的 UNIX 程序,包括 Linux 内核,各种网络服务程序,Xwindow 程序在内,哪一个是 IDE 搞出来的?我们实验室的 EDA 程序也没有一个是 IDE 弄的,我还知道Candence, Synopsys,Mentor 的高性能的图形界面 EDA 程序也都不是 IDE 写的。你信不信,微软的人在写 Windows 本身的时候也根本不用 IDE。微软内部程序员最喜欢的编辑器其实是 VIM,用 VIM 的微软程序员上次向乌干达的可怜儿童捐助了1000多美元,这是值得称赞的。
有一次某杂志采访一些出名的 Linux 内核程序员,包括 Linus 在内,没有一个人用IDE,有的人用 VIM,有的用 Emacs,只有 Linus 说"GNU Emacs is evil",但是其实他用的是一种跟 Emacs 有同样键绑定功能的 MicroEmacs。大家都是用编辑器编辑了程序文件,然后用 make 这样的自动工具调用 gcc 编译器完成编译工作的。甚至高级的 Windows 程序员也不用 IDE,他们可以从命令行调用 cl,nmake 来编译自己的程序。虽然这样的 Windows 程序员很少,但是他们却是最了解 Windows,最高明的Windows 程序员。
为什么 UNIX 程序员不用 IDE?明白了这个道理你就能体会到 UNIX 的设计思想了。首先,一个 IDE 集成了编辑器,编译器,汇编器,调试器,跟踪器…… 这个编辑器功能肯定比不上 VIM 或 Emacs,编译器比不上 GCC,汇编器比不上 as,调试器比不上 gdb,ddd, 跟踪器比不上 strace, ltrace, truss。你得到的是一套整合的低能的程序。如果你对调试器的功能不满意,你只好换用另外一套 IDE,但是这套 IDE 的热键,菜单,编辑器功能,按钮…… 跟原来那个有很大不同。你不得不花很多时间来熟悉新的环境,而不能保持原来的某些东西。
而在 UNIX 下就不一样了。你可以用你最喜欢的 VIM 编辑程序,你在 VIM 里可以调用GNU make,make 可以调用 gcc, ld, ... make 的出错信息可以被 VIM 捕获,VIM 能帮你在源程序里定位。你如果喜欢 icc, 你可以让 make 用 icc 而不是 gcc。你如果觉得 gdb 跟踪变量时比较麻烦,你可以用 ddd 来显示各种数据结构之间的关系。你还可以在 Emacs 里调用 gdb,那样就可以同步显示源代码了。而且 VIM 和 Emacs 还可以编辑很多其它东西,比如信件,LaTeX 文档,HTML,配置文件…… 你不用另外找一个什么编辑器来干这些杂活了。很多程序比如 Mutt, tin 都可以在内部使用 VIM,这样就更方便了。实际上 make 在其它方面还能帮你很多忙,我的每一个比较大型的 LaTeX文档都是用 make 维护的。
Linux 能干的高精尖的事情 Windows 都干不了
当然有很多事情是Linux/UNIX的专利了。因为 Windows 只能装在 PC 机上,好像以前也有 Alpha 可以使用 Windows NT,但是就是没见到有人用。PC 机的能力是很低的,像我们编程序处理 NP-Hard 问题的人,用 Windows 的机器显然速度不够,而且有时一个问题算上几天甚至几个星期,Windows 机器是以"死机"著称的,我们怎么能放心?所以几乎所有科学计算程序,EDA 程序,高性能图像处理程序都不是 Windows 的。他们有时也会移植一些给 Windows,但是常常降低那些程序的能力。你比较过 Windows 版本的 Mathematica 和 Linux 的有什么区别吗?
IBM 制造的最大的并行计算机有 8000 多个处理器,Windows 不可能有能力管理这么多处理器,它用的是什么操作系统?答案是 Linux。
《泰坦尼克号》电影里的三维动画,那么细腻逼真,Windows机器能做出来吗?不行。那也是 Linux 机器做的。
民航总局用来训练地情人员的虚拟现实训练设备,Windows 当然无能为力。那都是商业的 IRIX 机器。
UNIX 是最早支持 TCP/IP 网络协议的系统。它上面有很多可以互相协作的网络服务程序,它们经过多年的使用和修订,已经达到比较完善的程度。而就在1997年,微软的比尔盖茨还在扬言:"Internet 是没有前途的。" 微软的这个"远见卓识"大家应该都已见识,它后来加上的网络服务程序IIS漏洞之多,让公安部都频频发出警报,大家也是见识了的。
其实你知道了,Windows 没有一样有用的事情能比 UNIX 干的更好。
Linux 干不了的有用的事情 Windows 照样干不了
当然 Linux 不是万能的。它也有不能干的事情,电脑也有干不了的事情。但是 Linux干不了的事情,Windows 肯定也干不了。这些事情就是我们需要探索,需要努力的事情了。在你探索的过程中,Linux 必定是你的好伙伴。
不要把Linux和Xwindow掩盖起来!不要把我们的用户当成傻瓜。
什么?你早就知道 Windows 是垃圾?噢!你怎么不早说呢!害我废话这么多。嘿嘿。
"好了。你知道 Windows 是垃圾,你现在用什么?quot;
"Linux + Xwindow"
"那我问你,Xwindow 是什么样的?"
"不就是跟 Windows 差不多吗?只不过 'Start' 按钮比较方,而且上面不是一个Windows 标志,而是一个脚丫子。点击一下居然还有很漂亮的中文菜单。我喜欢!"
"你知道什么是'根窗口'吗?"
"不知道。从来没听说过呢?"
"根窗口就是遮盖整个屏幕的那个最大的窗口。"
"哪儿有什么窗口啊!我没有看到呢?"
你发现了问题吗?这些 Linux 用户说是在用 Linux 和 Xwindow,但是他们对 Linux和 Xwindow 几乎完全不了解。很多人用了那么久 Xwindow 都不知道根窗口是什么东西,不知道其实按钮也是窗口,不知道窗口管理器和其它程序有什么关系,大家都以为窗口上面的按钮是程序自己放上去的,不知道窗口?quot;class name","resource name"是什么东西。他们也不知道 .Xdefaults 是用来干什么的。特别是他们很多人都不知道 Xwindow 的字体是如何命名的,什么是 fontset,有了一个新的字体也不知道怎么安装。
他们被遮在 Linux 之上的一层一层的包装迷惑了,他们等待有图形界面的工具来帮助完成一切事情,他们认为 Linux 跟 Windows 一样,只是麻烦一点。他们知道 Linux内核很好,但是他们感觉不到 Linux 和 Xwindow 在操作层面的天生的先进性,随后不久就把 Linux 完全删除掉了。你发现没有,要用户理解 UNIX 和 Xwindow 的操作层面的先进性,才是留住用户的最好办法。如果用户体会不到操作时的方便和高效,内核再好他们也不会理会。
但是用摹仿 Windows 的作法来吸引用户,永远会失败的。因为 Linux 如果摹仿Windows那一套低效率的方式,那么 Linux 的这套"低效率方式"永远比不上Windows 的那一套"低效率方式"。那么用户就会说:"这个 Linux,没有一样比的上 Windows。"
Linux 天生就是继承了 UNIX 的高效的工作方式,为什么我们要把它掩盖起来?我们为什么只告诉用户 KDE 的菜单怎么用?我们为什么不能像早期的 Xwindow 书籍那样第一节就告诉用户什么是 X server, 什么是 X client,什么是 Window Manager, 什么是根窗口。第二章就告诉用户窗口有哪些属性,什么是 classname, resource name, hint,怎样使用 .Xdefaults, xrdb ……
在这里我又不得不说一下那些 Linux 的发行公司和写书的人,他们把 Linux 和Xwindow 包装起来,却没有从基本上告诉用户 Xwindow 的工作原理。很多书籍讲授的层次就是在Gnome, KDE 的菜单操作的层次,靠大量抓图来占篇幅,"繁荣"Linux 书籍市场。
现在很多人已经把能够利用别人的库写出一个好看的程序作为自己编程水平的象征。在这?quot;图形化","可视化" 的年代,你如果还在用 troff, LaTeX 写文档,你还在用VIM 自己编辑 HTML,用 Mutt 处理邮件,你还在用文本模式的 gdb 调试程序,你还在用Xlib 写程序, 你还在用 tin 上 USENET,你还在自己写 Makefile,写机器代码,你还在玩 Clossal Cave 这样的字符模式冒险游戏,那你就是老古董。
其实这种思想是错误的。虽然你是一个坚决的 Linux 支持者,但是你的思想是 Windows的思想。你认为图形界面,菜单,按钮就可以解决一切问题,就可以给你高效方便。你还是没能摆脱微软给你的潜移默化的东西。你其实离不开 Windows 那样的环境,你迟早会删掉自己的 Linux。
GUI vs. CLI
做一个坚定不移的"两面派"
大家看到这个标题是不是热血沸腾?两派大虾都可以围攻我了:
GUI派用户:"哇!我一看你这小子就是 CLI 的。要不然自己写什么 Makefile?用什么Mutt?"
CLI派用户:"切~ 你还用 X!高手都不用 X。你是 GUI 那边的。"
可怜的我:"555~~ 你们都不要我~~ GUI 和 CLI 就那么水火不容吗?"
计算机界这样的门派之分还很多。很有特点的就是 CLI 和 GUI 了。CLI (Command LIne)的狂热份子声称永远不用 X。我上次在实验室看到一个同学用一个 SecureCRT 登录到Sun 机器,然后用一个 vanilla vi 编辑程序,我建议他启动一个 GVIM 过来显示在Exceed 上可以有语法加亮。但是他坚决反对,说:"高手不用X。你想想,要是我在一个很慢的网络连接怎么用 X?而且好多服务器没有装 X 程序。"
但是我们实验室的网速可够快,Windows 机器都有 Exceed 啊,而且 Sun 机器有全套X 客户程序包括 GVIM。他说他是 CLI 的坚决拥护者,但是他却在用 Windows,他后来打开了好几个 SecureCRT,每次从文本框输入地址,用户名和密码,从下拉菜单选择"SSH2",然后点击"Connnect"。他还不断的夸SecureCRT是"网络管理员投票选出的最受欢迎的登录方式"。老天,SecureCRT 本身就是个 GUI 啊,他其实没有明白Xwindow 的好处。
你说我是 GUI 的?我虽然很少在 console 下工作。但是我对 bash, VIM 很熟悉,我可以让 bash 按照我的键绑定方式来工作。我可以在 rxvt 里使用 Mutt 来收发 email。我的每个桌面上都常常堆放着一打不同大小的 rxvt。我用 VIM 编辑 LaTeX。我自己写Makefile 来维护 LaTeX 文档。我有时用 mpg321 来放 mp3。我上BBS用的我自己写的expect 脚本。 好了,CLI 派的朋友可以收我做盟友了
你说我是 CLI 的老古董?我的 FVWM 被我配置为可以"手写操作",我只要画一个"r"就可以启动 rxvt,我只要画一个 "U" 就可以启动 GVIM,…… 我用 GVIM 语法加亮模式编辑程序,我用 Mozilla 浏览网页,…… GUI 派的现在好像认我做朋友了
好了。CLI 派的朋友,虽然我很喜欢命令行,但是我有时在屏幕上左右画一下就可以执行:
Module FvwmConsole -terminal rxvt -geometry 45x5-0+0 -bg gold -fg midnightblue -fn "-adobe-courier-medium-r-*-*-14-*-*-*-*-*-*-*"
你是不是现在又想把我逐出师门?
GUI 派的朋友,虽然我很喜欢窗口。但是我可以在 FvwmConsole 里输入:
All (rxvt) MoveToDesk
把我所有的 rxvt 移动到我现在工作的桌面。"这家伙,怎么这么快就叛变了!"
其实何必分什么 GUI 和 CLI,UNIX 和 Xwindow 都是工业标准,它们从设计那天开始就有非常灵活的用法,各个程序,不管是 GUI 还是命令行的都可以互相协作。UNIX 和X 是一家,何必搞的那么偏激,非此即彼?你从我上面的行为可以看出 GUI 和 CLI的模糊界线吗?我就是坚定不移的"两面派"。
UNIX 是简单的--
"我相信简单就是最好,如果太复杂,我是不能理解的。" -Seymour Cray
很多第一次用 Linux 的人会惊奇的发现,Linux 的程序居然不?quot;安装"就可以运行,程序拷贝到随便那个目录都可以用,而不是一定要占用你第一个分区的空间。程序的设置只是一些简简单单的文本文件。你根本不需要什么"注册表修改器" 就可以改变系统的设置。这就叫做简单,但是简单就是美。虽然这只是 UNIX 简单性的一个肤浅的认识,你已经体会到了某些东西。
但是简单并不意味着功能弱,并不意味着落后。相反,简单意味着强大,意味着生命力。
我不会再继续阐述我理解到的"UNIX 的简单",因为这个需要自己去体会。
UNIX 是永恒的
有人说:"Plan9 会取代 UNIX,Mach 会取代 Linux 内核。"
但是你如果是一个深入体会了 UNIX 的人,你就会知道:UNIX 的思想是永恒的,不管时过境迁,Plan9 是否代替 UNIX,UNIX 的灵魂都会在 Plan9 身上现形!
我为同一个设备写过 Linux 内核和 Windows VxD 驱动程序。写 Linux 驱动程序时,我对 UNIX 设计的完美的一致性,远见性所折服。UNIX 用同样界面的 read(), write()系统调用就可以对不同的对象:普通文件,设备文件,管道,管道文件,socket,……进行统一的读写操作。我跟本不需要写一个测试用的应用程序就可以对我的设备驱动进行测试,因为 cat, cp, dd, 它们也使用了同样的 read(), write(),设备和普通文件在应用程序眼里没有区别。在那个还没有 Smalltalk, 没有 C++ 的年代,UNIX 的设计者已经使用了所谓的 "面向对象方法"。对,C 语言也可以实现面向对象。
UNIX 的系统调用几十年都没有很大变化,这非但不是顽固,不进步的象征,反而是UNIX 的远见卓识的体现!这就跟 TeX 程序几十年都不变的情况差不多。这些才是真正的永恒的 master piece! 你应该改变所有软件都必需从 0.1, 1.0, 1.1, 1.2, 2.0,..., 3.0, 3.1, 95, 98, 2000, XP, ... 不断升级的想法。
Windows 就不同了,它在最开头只是一个 DOS 之上的图形包装而已。后来为了兼容以前的糟糕设计,不得不加上很多累赘。我写 VxD 驱动程序的时候就深有体会,Windows 95 程序对设备的操作只有用 DeviceIoControl,我不得不写了两个应用程序来对设备驱动进行测试。Windows 内核的不一致性和隐密性使我非常恼火。不过 Windows WDM驱动程序现在也有了 ReadFile, WriteFile,…… 那说明什么?那说明 Windows 在向UNIX 学习,或者有可能是某个 UNIX 设计人员在微软打了几天临工,顺手加了几个UNIX 的东西进去。这样做是没有用的,Windows 从一开始就是非常糟糕的设计,它的历史的包袱太沉重了,缝缝补补有什么用?它只能永远的被 UNIX 甩在身后!
UNIX 是强大的
让聪明人干任何他们想干的事情。
UNIX 的一个特点就是非常高的灵活性,Xwindow 也具有这种灵活性。这种灵活性体现在哪里呢?
UNIX 的程序一般都有很多参数,不管你现在用的着用不着,总有人需要某些参数。它们的行为很多都可以用配置文件来改变。比如 GNU bash, 通常缺省的命令行输入方式是 Emacs 方式,但是只要我编辑一个 .inputrc 文件,就可以把它变成 vi 的输入方式,而且我还可以自己绑定键序列到某些操作。我可以用 shopt 来设置它的很多特点,比如是否进行通配符扩展,是否可以把一个变量当作一个目录来cd,是否可以自动纠正某些明显的目录名打字错误 ……
UNIX 程序设计的思想是提供给用户"机制",而不限制用户制定"政策"。这是一个重要的尊重用户的作法。
我们再来看看 Xwindow。Xwindow 是一个出色的设计,它把显示服务器和客户程序分开。一个显示上既可以显示本机上的程序,也可以显示别的机器上的 X 程序,而它们都遵守你的窗口管理器的统一指挥,它们之间可以方便的传送剪贴版数据,各种事件 …… 比如有时我的 XFree86 上会出现四个不同机器上的 XTerm,两个不同机器上的 GVIM,…… 它们统一受本机上的 FVWM 指挥。
Xwindow 程序都具有很多很多命令行参数和 resource 参数。你可以随意的在命令行或者 .Xdefaults 文件设置所有的颜色,字体,尺寸…… 而且如果你用 xrdb 把 .Xdefaults 导入到根窗口,那么其它机器上没有经过配置的同样的程序,显示到你的机器上的时候也会遵守同样的外观规定。
Xwindow 的窗口具有 Property, 也就是一些可以自己定义的共享数据(原子)。正是因为这些 Property 的存在,使得 Xwindow 具有无比强大的生命力。X 的窗口管理器和其它客户程序之间并没有统一的协议,但是后来出现了 ICCCM(客户程序间通信规范),这个规范就是通过 property 定义的。现在又有人定义了一套"扩展的窗口协议(EWM Hints)",使得Xwindow 可以具有某些 Windows 的特征,比如一个工具条程序可以告诉窗口管理器:"这个屏幕下面被我占据了24个像素的空间,你最大化程序的时候不要越过这个界线。"
一个强大的窗口管理程序比如 FVWM,它收到这样的提示时,可以答应工具条程序的这个要求,也可以不答应。一切选择的权力在于谁?当然是用户了!
你想想,是不是有些 Windows 程序常常弹出一个窗口要你选择 "Yes or No"?你不点击它它就不下去。你觉不觉得你的程序在侵犯你的尊严?你是一个人,一个智慧的生物,怎能受到一个程序如此的待遇?
还有就是很多 Windows 程序把人当成傻瓜,而它是"智能程序"。比如,有一个程序就是喜欢把你的每句话第一个字母都变成大写,我不说它是谁了,你遇到的时候就知道了。
如果连"一句话开头一个字母要大写"这么明显的问题都需要程序帮你纠正的话,人脑还用来干什么?况且如果你故意想要不大写的话,那就更麻烦了,我楞是没有从它那一大堆菜单里找到怎么关闭这个愚蠢的选项。
只有符号才能完全操纵计算机。
我们来说说很多初学 Linux 的用户。虽然他们在用 Linux,但是他们打心眼儿里是觉得Windows 的工作方式好,他们希望 Linux 有一天能"像Windows那样"。你说:"我的鼠标一点,我菜单一拉,…… 就可以完成我的操作。" 但是我要告诉你:"Linux 从来没有摹仿 Windows,将来也不会。Linux 从诞生之日起,它的工作方式就比 Windows 的先进。
Linux 属于能勇敢面对符号的人。只有符号才能完全操纵计算机。"
看看优秀的 UNIX 程序,XFree86, FVWM, VIM, Emacs, proftpd, Mutt, wget, tin, ... 没有一个不是用配置文件来设置选项的。为什么这些程序没有方便的菜单可以用来配置?难道它们的设计者就那么低能,连个图形配置界面也写不出来?
当然不是。因为图形界面配置方式的能力是极其有限的,而配置文件和程序语言的表达能力却是无限的。用图形界面配置这些程序的话,如果你想达到配置文件的效果,你需要成百上千的菜单,checkbox, radio button, ... 到时候你根本没办法找到你需要修改的地方了!而各个程序的配置文件的语法都有很多相似之处,一般就是一些命令,设置一些变量,参数,…… 一旦用会了一个,其它的也就容易理解了。如果你用惯了 awk, sed, Perl,你会觉得那才是真正的自动化啊。
鼠标虽然是很好的工具,但是它的表达能力是有限的。你不可能光用鼠标就让电脑完全明白你的意思,它毕竟只有3个按钮。看看我的MetaPost页你就能体会到鼠标的这一弱点。所以我们虽然很喜欢鼠标,但是却不能完全依赖它。
各个小程序的完美配合
这就是UNIX最重要的特点了,它就是UNIX设计的思想。让每个程序只具有一项专门的能力,然后让它们合作。Xwindow也继承了这种好传统。这恐怕就是Windows和其它操作系统望尘末及的地方了。UNIX 程序设计之统一,配合之完美,真使我难以置信!shell, grep, find, awk, sed, make, Perl, Emacs, vi, tin, Mutt, ... 它们是那么的具有一致性!你一旦学会了 sed 的正则表达式,其它程序基本上都能用了。你一旦学会了vi 和 VIM, 你会发现它的操作是那么的有规律性,似乎vi的设计者在几十年前就已经设计好了 VIM 在今天的完美而统一的操作方式!而且vi的操作还体现在 Mutt, tin 等很多程序中。你甚至可以把 bash 设置为 vi 的输入方式来输入命令行,我就是这么做的。一个程序可以调用另外一个程序来得到数据,可以把数据交给它处理后返回来,可以在自己的窗口里"嵌入"另外一个程序。
在 Windows 和其它非 UNIX 操作系统中,这种合作是非常困难的。我曾经在Windows下使用 Perl来进行一些自动工作。但是 Windows 的文件操作,管道是如此的不稳定,程序之间基本不能合作。你别想在 Visual Studio 窗口里面嵌入 UltraEdit 编辑器,你别想用一个 expect 脚本来控制 telnet 到水木清华BBS。
Windows 的程序都是大而全,大而杂,所有的电子邮件程序都需要自己提供编辑器,自己发送和收取邮件,自己显示邮件的附件。每一个BBS程序都提供自己的Virtual Terminal, 自己的通讯代码。每一个 IDE 都自己提供编辑器,编译器,汇编器,调试器。人们为了使用一种新的程序,需要适应所有这些它提供的界面,而不能使用自己喜欢的编辑器的键绑定,菜单组织…… 不能 DIY!
你要知道,最高级的电脑是定做的,自己想要什么什么CPU,什么主板,多少内存,什么硬盘,键盘,鼠标,显示器都是自己选择的。最高级的滑板,自己想要什么牌子的版面,什么牌子的沙,什么桥,什么轮子,什么轴承,也都是自己选的。最高级的古球拍,木板,胶皮,海绵,胶水都是可以自己选择…… 而用 Windows 程序,你得到的是大杂烩,就像你去买"品牌机",只有那么几种配置,而且附带很多你不需要的软件和服务;就像你去买组装好的滑板,你想要大一点的轮子和窄一点的板子,但是你没有这种选择余地!Windows 程序就相当于最廉价,最次的滑板。但是它却会花你更多的钱,因为一旦一个部件坏了,或者你不喜欢了,你不能另外找一个好的换掉它,你必需重新买全套配件!
而 UNIX 和 Xwindow 就是高档的"组装货"。比如我用 Mutt 的时候,我可以用 VIM也可以用 pico 来编辑邮件,我可以用 ImageMagick 也可以用 xv 来显示附件里的图片,我可以用 lynx 把 HTML 附件转成文本嵌入窗口中,我也可以把 HTML 附件交给Mozilla 图形显示。我可以让 GnuPG 帮我把邮件进行数字签名和加密,我也可以用其它 PGP 程序。
我想让 Postfix 而不是 sendmail 帮我发出邮件,我想让 fetchmail 帮我收邮件,转发给 postfix,然后被我自己写的Perl过滤器处理…… 这一切我都可以办到!我可以选择我最喜欢的专门的程序来完成专门的工作,然后把它们结合在一起,我也可以分别得到它们的好处。
学 UNIX 绝对不是浪费时间
有人告诉我:"你看我用 Windows 什么都不用学。而用 Linux,光是安装就花了我一个星期!"
首先,我要告诉你的是,你装 Linux 花了一个星期,不是因为 Linux 不好装,而是因为你已经习惯了 Windows,对 Linux 最初难以理解而已。你想一想你最初安装Windows的时候呢?你花了多少时间搞明白什么是硬盘分区?什么是盘符?什么是目录?你认为Windows 就是那么容易可以学会的吗?虽然你觉得没花时间学,但是你以前在用别人的机器的时候已经耳濡目染,自然就了解了。而且由于你想要 Linux 和 Windows 并存于硬盘上,又增加了安装难度。而且你肯定没有得到有经验的 Linux 用户的帮助,否则他们会在20分种之内帮你搞定。一个星期也太夸张了.
如果一开始用的就是Linux就没有这个问题。你想想如果你没有用过 windows,你肯定会很习惯 /etc, /usr, /usr/local ,... 而不是 C:, D:, E:, ... 是不是?如果你只用过Linux,你第一次用 windows 时恐怕也会问:"/bin 目录哪里去了啊?"
最重要的是,你用惯了的UNIX工具,它们可以伴随你一生,而不会那么容易变化或消失。你可以永远不用再换另外的工具了。除非那个工具比你这个好的太多,而且可以完全模拟你现在的工具。
我们实验室一个60多岁的老师,用vi, cc, make, ...都几十年了,他以前的经验绝对没有白费,而且教会了我们一批又一批的学生。vi 伴随着 UNIX 的最初发行而诞生,直到今天还是世界上头两号编辑器之一!有些人的 FVWM 配置文件已经用了 10 多年,现在完全不经修改还可以用。
看看 Windows 的工具,你从 Borland C++ 换到 VC, 就必需适应新的环境:菜单不同了,颜色不同了,按钮不同了,帮助信息不同了,热键不同了,编译器参数,调试器功能也不同了,…… 那个时候恐怕花要花你很多时间去适应。当你刚刚适应了 VC, 你又要换成VJ, PowerBuilder, C++Builder, ...
很多windows程序员都是这样,开头在dos下用Turbo C, 然后是 Borland C, VC, C++ Builder, ......不断追赶微软的潮流。而且微软的SDK, MFC, .NET …… 什么都在不断变化,不断出问题,又不断的在修改…… Windows 程序员不得不买又厚又重的 Microsoft Press 的书籍,看了才一个月,又过时了。今天你才学会了写 VxD,明天你就必须用WDM 了。你不得不注册 MSDN 才能赶上 Microsoft 的步伐。很多人说:"计算机是贵族的专业。" 这就是微软一手造成的。
这些东西才是没完没了的浪费大家的时间和金钱的。这是是浪费生命!我们为什么不使用从诞生就那么一致和完美的 UNIX?你需要理解先进工具的设计理念。UNIX 的工具就像我们用的汽车,它的离合器,油门,刹车,方向盘,后视镜,永远都在同样的位置。用惯了的话,你对你的汽车的每一个部件都会了如指掌,甚至你自己都可以修车了。这难道不好吗?
有人说:"你说我们需要了解 UNIX,难道你要开车还必须了解汽车的结构吗?" 你去问问开车的司机,哪一个不了解汽车的结构的,那他的驾照就是混来的。你难道想要傻瓜型的"微软牌汽车"吗?我们来看看:
你买的微软牌汽车最开头只有一个座位,每加一个座位你得向汽车公司付钱。车上的防撞气囊不时会冒出来,说是为了你的安全。每开100英里要大修一次,每过一年要换一次引擎。附带的,你还必须换用由微软汽车公司指定的石油公司提供的新型号的机油。你的车出了问题,但是法律规定,你不准私自拆开你的汽车来修理,你必需到微软汽车公司指定的维修点去,需要付相当多的钱才能修好一个小毛病。
最可气的是,你每换一个型号的微软牌汽车,它的刹车和离合器都在不同的位置,你需要重新去考驾驶执照。如果这辆汽车在途中刹车失灵,你受了重伤,你也不能状告微软汽车公司,因为你买来汽车之后必须签一个合同,说"由于微软牌汽车对你和家人造成的一切死伤,微软概不负责。"
怎样完全用 GNU/Linux 工作
说了这么多 Windows 的不好。我还没有告诉你我怎么用 Linux 处理有些必要的事情。半年以前我由于中文老是配置不好,一直是双系统,不时需要重起到 Win2k 来处理汉字。后来我找到了 miniChinput, XSIM 和 SCIM 输入法。这下可以处理汉字了。而且 VIM 和Emacs 对汉字支持越来越好。我的大部分文本是用 VIM 编辑的,包括程序,信件,网页,LaTeX 论文,MetaPost 绘图语言。
我不用 Word 这样的程序写论文,而是用 LaTeX,因为这是世界上效果最好,最方便的论文工具,是大多数学术杂志要求的格式。幻灯都是用 ConTeXt 做的,用起来很简单,而且效果非常漂亮。你可以看看我的TeX介绍。
至于绘图,你可以用很多可视化的工具,比如 xfig,dia。但是对于我来说,任何可视化的工具都不能完成某些任务,我需要一种可以精确描述图形的语言。我找到了MetaPost。它简单又好用,而且效果是世界一流的。我的插图,如果不是图像,都是MetaPost 画出来的。
我曾经抱怨 mozilla-mail 经常突然消失,损坏我好几封快要完成的信件。后来我发现mozilla 的邮件处理程序确实是不稳定的,功能又弱,有经验的 UNIX 用户都不用这样的程序。Mutt 是一个非常稳定可靠的 UNIX 邮件处理程序,而且功能非常强大。我曾经为 Gnome 和 KDE 的不稳定而烦恼。现在我找到了非常强大的 FVWM。KDE,Gnome也能和 FVWM 一起工作。虽然 Gnome 和 KDE 总体不稳定,但是某些部件程序还不错,很多 gtk, Qt 的程序也很不错,它们很多都是可以独立于这些桌面环境运行的。
Linux 有很多强大方便的工作方式是 Windows 没有的,或者有类似的东西,但是很差劲或者用起来不方便。比如 ssh 服务,rsync,cvs,expect ……
结论
我写这么多的目的是什么?我希望喜欢 Linux 的朋友,完全清除微软和 Windows 灌输在你脑子里的谬论,别再相信它们所谓的"新技术",别再追赶 Windows,因为追赶Windows = 倒退。马克思有一个思想很重要,"新生事物并不一定是在最近出现的。"
UNIX,Xwindow, TeX 虽然都比 Windows 先出现,但是它们才是先进生产力的代表。我们要清楚的认识到什么才是真正的现代化,什么才是真正的自动化。
消除学计算机很难的幻觉,勇敢的拿起像 bash, FVWM, TeX, VIM, Emacs, Mutt ……这样强大的程序,勇敢的面对符号。不要再埋怨"Linux 为什么不能像 Windows 那样",不要再浪费时间试用这样那样的程序,不要再忙着升级。你需要理解 UNIX 的工作方式,因为那是大多数科学家的工作方式。Linux 可以成为你的好朋友,你需要认识它,了解它,信任它,才能完全的靠它来高效的工作。当然,在游戏机,手机,掌上电脑里,或者在用电脑来娱乐的时候,用一些"傻瓜软件"还是不错的.
我希望小学,中学的计算机老师能够提高自己的素质,在孩子们的启蒙教育中充分利用Linux 神秘的特点,引起孩子们对数学,对符号的好奇心。诱导他们用计算机来解决世界上的有趣问题,而不要把教学的范围局限于计算机的操作和它自身的问题。
附录: 我用来处理日常事务的 Linux 程序
好了好了。我知道你发现自己应该转向 Linux,你很后悔当初为什么中了微软的邪。但是不要着急。因为这些东西本来只是工具,它们是用来完成你的主要任务的辅助而已。你以前选错了工具,这不要紧。你还是拥有你自己原来的专业技能,那才是最重要的。工具的东西只有慢慢适应转换,不能一蹴而就,否则你会感到非常没意思,甚至放弃。
如果你只想做一个像我这样的普通用户,主要目的是用 Linux 来完成自己的任务,那就可以不用系统管理员或者网络管理员的标准来要求自己,因为当一个系统和网络管理员确实很辛苦。这里我对实验室的网管同学鞠一躬,谢谢你的指点和帮助. 不用把你的机器当成网络服务器,不用开放没有必要的服务,设置好 ssh, ftp 已经足够了。这样会省去了解很多没必要了解的东西的时间。不用过度考虑"安全",因为 Linux 缺省已经很安全了。不过你有兴趣了解更多那也无妨。
下面给出一些推荐使用的可以处理一般事情的程序。至于你的专业上要用到的科学和工程软件比如 Matlab, Mathematica, Maple, HSpice, Design Compiler, …… 还有其它物理上的,化学上的,生物上的 …… 都必然有 Linux 和 UNIX 的版本。当然他们很多不是免费的,不要总是觉得什么都应该免费,自由不等于免费。它们是经过很多人辛勤劳动的产物,是可靠的程序,它们物有所值。
下面列出我常用的一些 Linux 程序。一个列表里可能有很多,那是为了方便你来选择,我列出了比较信得过的。但其实很多只有第一个是我真正在用的,我不喜欢试用程序。我不是一个合格的网络管理员,我的服务器都只设置了我自己需要的功能,那样可以省去我很多麻烦。
Shell: bash。它结合了 csh 和 ksh 的优点,并且有 readline 功能,你可以随意绑定自己的键盘。
编辑器: VIM, Emacs。
程序开发: GCC, make, ld, Scheme48, j2sdk, Perl, Python, Tcl/Tk ...
论文,幻灯工具:LaTeX, ConTeXt
绘图工具:MetaPost。这个语言太强了,以至于我只用它了。你不熟悉的话可以用xfig, dia 来画一些流程图之类的图片。
图像处理:ImageMagick。其中的 import 程序可以屏幕抓图,convert 程序可以转换图像格式,display 可以显示图片和简单编辑(缩放,换质量,转格式,简单绘图,简单虑镜)。通常我就这么点需要。如果你要更强大的图像工具可以用 Gimp, 它几乎和Photoshop差不多。
自动管理工具:make。我可以用make来自动编译程序,自动编译文档,自动更新插图…… 全自动,而且不会重复劳动。
数值计算程序:SciLab。这个程序基本上可以代替 Matlab。
代数计算程序:MAXIMA。这个程序基于世界上最老的计算机代数系统之一: 由美国能源部(DOE)发行的 MIT Macsyma 系统。它是用 Common Lisp 实现的。很多现在的符号计算程序比如 Maple 都从 MAXIMA 身上学到很多东西。它现在经过 DOE 批准以GPL发行,永远是一个自由软件。
加密程序:GnuPG。我的 PGP 密钥就是它搞出来的。
打包,压缩程序。什么都有: tar, gzip, bzip2, zip, rar, ...
虚拟光驱程序。Linux 不需要虚拟光驱程序,直接 mount 就行了。
ftp 服务器:proftpd, vsftpd。proftpd 功能很强,但是我只用了最简单的一种设置。
WWW 服务器:apache。(我一般没有开)
ftp 客户程序:lftp,ncftp。它们都是文本方式操作的,但是比起图形界面的方便的多。比如 lftp 几乎具有 bash 的所有方便功能,Tab 补全,bookmark, queue, 后台下载,镜像…… Linux 也有图形界面的 ftp 客户程序,但是大多不稳定,有很多问题。这就是很多人抱怨 Linux 不如 Windows 的一个小原因。还有很多人用 Wine 模拟 Windows 的leapftp,其实 lftp 比 leapftp 好很多,你需要的只是适应一下。
自动下载工具:wget。它非常稳定,有一次我下载一个程序,用 IE 和 Mozilla 下载回来的文件都是坏的,最后还是 wget 可靠的传输了数据。用它甚至可以镜像整个网站,比起WebZip 这样的 Windows 程序强多了,而且不会因为你不付钱就在下载回来的网页里强制插入广告。
虚拟终端:rxvt, xterm, gnome-terminal, mlterm, ...
X server: XFree86
窗口管理器:FVWM。编译加入了 libstroke。
中文输入:XSIM。被我修改过以适应 FVWM 的需要。另外推荐你还可以用 SCIM。
email 处理:Mutt + Postfix + fetchmail
看 PDF, PS, DJVU 文件:Acrobat Reader, xpdf, GhostScript, gv, djvu工具包和netscape 插件。
看CAJ文档。我从来不看CAJ之类的文档,如果找不到PDF或PS,直接去图书馆借最好。
看网页:Mozilla, Phoenix, lynx。Mozilla-Xft 的显示效果比IE 好很多。
英汉字典:IBM智能词典,星际译王。
编辑网页:我用VIM 直接写 HTML。你如果想要图形方式的可以用其它的比如screem, BlueFish。
登录其它 UNIX, Linux 机器:openSSH, telnet。 我喜欢用 openSSH 把其它机器的X 程序通过 ssh 加密的隧道传到我机器上显示。
登录 Windows2000 server 的 display service: rdesktop,...我有一天试了一下,不错。后来就没有用过了。
同步程序:rsync。我用 rsync 通过 ssh 来跟某些机器同步数据,或者做自己机器上不同目录间的同步。
上BBS:rxvt(或任何一种终端) + telnet + chatbot(helloooo 机器人的程序)
QQ, ICQ: 我没有 QQ 或 ICQ。不过你可以用 Gaim, 它同时支持 QQ, ICQ 和很多其它的即时通信方式。ICQ 用户也可以用 Licq。
放录像:MPlayer, RealPlayer。MPlayer 太好了,直接就可以放 VCD, DVD, divx, wma, wmv ... 用 Windows 的同学都很羡慕我,说 Windows 要放这个需要大堆插件。rm 最好还是用 realplayer 放,它也是免费的。
放音乐: xmms(mp3,ogg都可以), mpg321(放mp3), ogg123(放ogg)。mpg321 不如xmms管理音乐文件那么方便,但是有时我还是用 mpg321 放 mp3 作为背景音乐,因为懒得开一个xmms窗口:-)
游戏:我觉得 KDE 的那个 ksokoban(推箱子),很好玩 :-)
看 Word 文档。请 Word 用户把文档全部转为 PDF 或 PS 再给我,文档里没有特殊的格式干脆就用文本吧,何必那么麻烦。以前很奇怪的是,通知里本来没有什么特殊的格式居然还要发doc附件的email。现在好了,我们系发通知都用文本,PDF,甚至图片了。
其它程序:还有很多我需要用而你不一定用得着的。比如,Doctor Scheme,
Scheme48, Scsh, kawa...这些程序只有 Doctor Scheme 有Windows版本。还有很多幕后工作但是你一般不察觉的:xinetd, telnetd, sshd, crond, atd, lpd, ... 他们都比 Windows 的对应者强的多,或者根本没有对应者。
附:
写给支持和反对《完全用Linux工作》的人们
作者:王垠
在一阵阵唾骂和欢呼声中,《完全用linux工作》被转载到了天涯海角。很多人支持我,也有很多人唾骂我。我不知道它是怎样流传到那么多地方,其实我不知道它都被
2005年09月28日 星期三
ubuntu中文
"Ubuntu" 是一个古非洲语单词, 意思是 "乐于分享". 班图精神也意味 "我和他人紧紧相连, 密不可分, 我们都在同一种生活之中. " Ubuntu Linux 也将班图精神带到了软件世界。
链接如下:


