14.1. 禁止非root用户登录系统
在/etc目录下新建一个nologin文本文件,内容随意。当系统发现该文件,就会禁止其它用户登录,并显示该文件内容。 14.2. 禁用CTRL+ALT+DEL组合键,防止非法重启电脑。
修改/etc/inittab文件,注释掉以下内容即可: 由 ca::ctrlaltdel:/sbin/shutdown -t3 -r now 改成: #ca::ctrlaltdel:/sbin/shutdown -t3 -r now
14.3. 重新配置键盘布局debian:~#dpkg-reconfigure console-data
14.4. 在终端下使用中文
可安装zhcon平台,该平台自带多种输入法,包括拼音和五笔。zhcon要求内核支持framebuffer功能。软件的安装方法很简单,使用以下命令即可: debian:~#apt-get install zhcon
14.5. 内核模块配置工具modconf
我们可利用该工具增删正在运行的内核模块。修改可保存,下次重启服务器修改仍有效。它修改的配置文件是/etc/modules。 14.6. 配置文件备份技巧
Debian系统有很多配置文件,系统的功能都是通过这些配置文件来配置的,所以这些文件是非常重要的,特别对系统管理员来说,在日常工作都需和这些文件打交道。作为一个合格的系统管理员,应该要确保系统的稳定,并在出错后能迅速恢复。所以在修改这些配置文件前,应该以.old为后缀进行备份,并修改文件属性为只读,确保能准确恢复到初始状态。 debian:~# cd /etc debian:~# cp fstab fstab.old debian:~# chmod a-w fstab.old
14.7. 用write命令与其他终端通信
使用write username [tty]命令可与其它终端在线通信。用Ctrl+D结束输入并发送信息。wall命令可向所有用户发送信息。 在.profile文件中设置mesg n命令可阻止其它用户用write发送过来的信息。 14.8. /etc/issue文件的作用
/etc/issue是一个文本文件,里面的内容会在用户登录前被显示在终端上。/etc/issue.net文件是供网络登录的用户使用的。 14.9. /etc/motd文件的作用
/etc/motd也是一个文本文件,它是message?of?today(今天的信息)的缩写,里面的信息会在用户登录后显示,该文件经常被用作系统公告,用于把最新的信息通知终端用户。 14.10. 用losetup虚拟光驱
使用losetup个程序可在Linux下实现虚拟光驱功能。 14.11. /proc目录内的内存文件介绍
/proc目录下的文件包含大量系统的信息,通过cat命令可直接查看。 · /proc/cpuinfo,CPU相关的信息,如主频、型号、缓存等。 · /proc/interrupts,中断信息。 · /proc/ioports,设备IO端口信息。 · /proc/meminfo,内存信息,如MemTotal、MemFree、Cached等。 · /proc/partitions,分区信息。 · /proc/pci,PCI设备信息。 · /proc/swaps,Swap分区的信息。 · /proc/version,Linux版本信息。 14.12. 常用设备的I/O地址和中断
Table 14.1. 一般设备的设定值
14.13. /var/run/utmp文件的作用
/var/run/utmp是一个二进制文件,记录当前登录系统的用户信息。可用who或w命令显示当中的内容。如: debian:/var/log# w 23:23:46 up 3:14, 3 users, load average: 0.61, 0.60, 0.45 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root :0 - 20:12 ?xdm? 33:58 1.91s x-session-manager root pts/1 :0.0 23:19 8.00s 0.28s 0.21s ssh reomte root pts/3 :0.0 22:31 0.00s 0.23s 0.00s w
14.14. /var/log/wtmp文件的作用
/var/log/wtmp也是一个二进制文件,记录每个用户的登录次数和持续时间等信息,可以last命令输出当中内容,如: debian:/var/log# last root pts/1 :0.0 Thu Jul 7 23:19 still logged in root pts/3 :0.0 Thu Jul 7 22:31 still logged in root pts/3 :0.0 Thu Jul 7 20:17 - 22:24 (02:06) root pts/1 :0.0 Thu Jul 7 20:14 - 22:39 (02:24) root :0 Thu Jul 7 20:12 still logged in reboot system boot 2.6.10 Thu Jul 7 20:10 (03:17) ....
14.15. 用sysvinit管理服务进程
安装sysvinit软件包可管理debian中启动的各种服务。 14.16. sync命令的作用
sync命令可强制把缓存中所有未保存的数据写回磁盘中,有效保证数据的完整性。 14.17. 查看IDE硬盘参数信息
/proc/ide/hd*/media文件只有一行,记录ide设备的类型(cdrom、disk、type、floppy)如: disk #表示是硬盘 通过/proc/ide/hd*/model文件,可以查询到ide设备的型号信息,如: IBM-DJSA-220
通过/proc/ide/hd*/geometry文件,可以查询到ide设备的参数(cylinders/heads/sectors)。如: physical 16383/16/63 logical 38760/16/63
14.18. Linux下各种压缩文件格式介绍
在Linux上有各种的压缩文件格式,不同的压缩格式用不同的程序来处理 · .gz压缩包用gunzip程序 · .Z压缩包用uncompress程序 · .zip压缩包用unzip程序 · .bz2压缩包用bunzip2程序 14.19. 时区配置
UTC表示国际标准时间,CST表示中国标准时间,UTC比CST慢8小时。使用tzconfig工具可以配置本机的时区。 14.20. 用crontab管理自动化任务
crontab -e命令可以创建当前用户的定时任务,如每天8点发一封邮件给管理员等。设置格式如下: m h dom mon dow command 分钟(0-59) 小时(0-23) 日期(1-31) 月份(1-12) 日/周(0-7) 命令
每小时的01分执行一次ping命令的示例: 01 * * * * ping -c 3 192.168.1.254
几种特殊符号: * 星号表示任何时候 , 逗号表示不连续的时间段,如01,03 * * * * ping -c -3 192.168.1.254,每小时的01和03分都执行一次ping命令 - 中横扛表示连续的时间段,如10 01-08 * * * ping -c -3 192.168.1.254,1点到8点每个小时的10分都执行一次ping命令 /n 表示每隔n个单位间隔,如*/07 * * * * ping -c -3 192.168.1.254,每隔7分钟执行一次ping命令 用crontab -e命令设置的是用户级的任务计划,系统的任务计划在/etc/crontab文件中设置,它是一个文本文件,设置的语法是一样的。如: # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file. # This file also has a username field, that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * root run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || run-parts --report /etc/cron.daily 47 6 * * 7 root test -x /usr/sbin/anacron || run-parts --report /etc/cron.weekly 52 6 1 * * root test -x /usr/sbin/anacron || run-parts --report /etc/cron.monthly #
run-parts命令后指定一个目录名为参数会自动搜索并执行该目录下所有的可执行文件。 14.21. 用Ctrl+r组合键查找命令历史
在bash shell中查找命令历史是很方便,使用Ctrl+r命令即可进入查找状态,依次键入曾经使用过的命令,bash shell会自动匹配相似的命令行。 14.22. 用xvidtune工具调整显示模式
xvidtune工具可以调整显示模式。xrandr工具可显示和设置显示模式。 14.23. 用apropos命令搜索man
apropos命令可查找命令名和相关描述。该命令的效果等同于man -k命令。 debian:~# apropos reset BIO_ctrl_reset_read_request (3ssl) - BIO pair BIO BIO_reset (3ssl) - BIO control operations kbdrate (8) - reset the keyboard repeat rate and delay time reset (1) - terminal initialization reset_prog_mode (3ncurses) - low-level curses routines reset_shell_mode (3ncurses) - low-level curses routines resetty (3ncurses) - low-level curses routines SSL_clear (3ssl) - reset SSL object to allow another connection XmbResetIC (3) - reset the state of an input context XResetScreenSaver (3) - manipulate the screen saver xtrapreset (1) - XTrap sample clients Xutf8ResetIC (3) - reset the state of an input context XwcResetIC (3) - reset the state of an input context
14.24. 用lsusb列出usb设备信息debian:~# lsusb Bus 001 Device 001: ID 0000:0000 Bus 001 Device 002: ID 05e3:1205 Genesys Logic, Inc. Afilias Optical Mouse H3003
14.25. 删除带"-"符号文件
用rm ./-foo命令可删除前面带"-"符号的文件名。 14.26. 安全地远程运行X程序
使用SSH构建X隧道是增强X系统安全性最好的方法之一,使用SSH将远程X服务器的显示通过隧道连接到本地显示器。配置ssh服务器,打开X隧道转发功能。 X11Forwarding yes
在远程客户端通过SSH远程登录服务器运行X程序。 debian:~# ssh -X 192.168.0.2 gimp
14.27. TCP可信端口范围
在Linux中,TCP端口0--1023的所有端口被称为可信端口,只有具有超级用户特权的进程才能监听可信端口进入的连接或者从这些可信端口发起的到远程服务器的连接。
14.28. 安全删除文件
使用shred命令可以安全删除Linux系统中的文件,以防止黑客们从硬盘恢复用rm命令删除的文件。示例: shred -u -z -n 20 text.txt text.txt是要彻底删除的文件 -u选项表示删除文件 -z选项表示用0覆盖 -n 20选项表示重复20以确保文件被彻底删除 debian还提供一个secure-delete软件包用以处理安全删除文件的事宜。它包含有4个工具,分别是: srm,shred的高级版本,用以安全擦除文件 smem,用以安全擦除内存 sfill,用以安全擦除硬盘上的空余空间 sswap,用以安全擦除交换分区 14.29. 在man中执行shell命令
在man页面中输入!号就可执行shell命令。该功能可使我们能及时测试man页面中介绍的命令参数和选项。 14.30. 用dd命令备份引导区信息
磁盘引导区的信息是很重要的,一旦破坏或丢失就会不能启动系统。所以我们有必要为它做个备份。在Linux下用dd命令可完成该工作。 debian:~# dd if=/dev/hda of=bootsector.img bs=512 count=1
生成一个bootsector.img文件,大小为512个字节,包含引导区所有信息。恢复过程如下: debian:~# dd if=bootsector.img of=/dev/hda
14.31. 用dd命令生成任意大小的文件
用dd命令可以生成指定大小的测试文件。 debian:~# dd if=/dev/zero of=aaa bs=1k count=1024
上面的命令会生成一人1M大小的文件,文件内容是以/dev/zero的零值填充的。if表示源,of表示目的,bs表示每次输出大小,count表示一共输出多少次。 14.32. 查找setuid和setgid程序
查找setuid的程序: # find / -perm +4000
查找setgid的程序: find / -perm +2000
14.33. 查处二进制文件的工具
查看二进制文件可使用od、hexdump和xxd工具。下面是一个使用xxd的例子: debian:~# xxd boot.bin 0000000: 8cc8 8ed8 8ec0 e802 00eb feb8 1e7c 89c5 .............|.. 0000010: b910 00b8 0113 bb0c 00b2 00cd 10c3 4865 ..............He 0000020: 6c6c 6f2c 4f53 2077 6f72 6c64 2100 0000 llo,OS world!... 0000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000040: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00000a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00000b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00000c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00000d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00000e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00000f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000100: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000110: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000120: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000130: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000140: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000150: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000160: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000170: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000180: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000190: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00001a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00001b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00001c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00001d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00001e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00001f0: 0000 0000 0000 0000 0000 0000 0000 55aa ..............U.
14.34. 用lsof显示系统打开的文件debian:~# lsof |more COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME init 1 root cwd DIR 3,3 4096 2 / init 1 root rtd DIR 3,3 4096 2 / init 1 root txt REG 3,3 32472 731577 /sbin/init init 1 root mem REG 3,3 9684 162760 /lib/libdl-2.6.1.so init 1 root mem REG 3,3 1335536 162748 /lib/libc-2.6.1.so init 1 root mem REG 3,3 83512 406952 /lib/libselinux.so.1 init 1 root mem REG 3,3 220764 162603 /lib/libsepol.so.1 init 1 root mem REG 3,3 117340 162623 /lib/ld-2.6.1.so init 1 root 10u FIFO 0,13 4624 /dev/initctl ksoftirqd 2 root cwd DIR 3,3 4096 2 / ksoftirqd 2 root rtd DIR 3,3 4096 2 / ksoftirqd 2 root txt unknown /proc/2/exe events/0 3 root cwd DIR 3,3 4096 2 / events/0 3 root rtd DIR 3,3 4096 2 / ...
14.35. 使用strings检查文件中的可打印字符
该命令可以用以文件的安全检查,检查文件中是否有passwd、backdoor等敏感字符。 debian:~/c/kernelmodule# strings HelloModule.ko __remove_pages __remove_pages license=GPL vermagic=2.6.17.1 mod_unload PENTIUMIII gcc-3.3 depends= <1>hello, world <1>Goodby,cruel world HelloModule
14.36. 使用bing测试两台主机间的带宽.3debian:~# bing 192.168.6.246 192.168.3.2 -c 3 BING 192.168.6.246 (192.168.6.246) and 192.168.3.2 (192.168.3.2) 44 and 108 data bytes (1024 bits) 192.168.3.2: 61.255Kbps 16.717ms 16.325195us/bit 192.168.3.2: 80.573Kbps 12.709ms 12.411133us/bit 192.168.3.2: minimum delay difference is zero, can't estimate link throughput 192.168.3.2: 40.960Mbps 0.025ms 0.024414us/bit 192.168.3.2: 39.385Mbps 0.026ms 0.025391us/bit 192.168.3.2: 37.926Mbps 0.027ms 0.026367us/bit 192.168.3.2: 39.385Mbps 0.026ms 0.025391us/bit 192.168.3.2: 40.960Mbps 0.025ms 0.024414us/bit 192.168.3.2: 39.385Mbps 0.026ms 0.025391us/bit 192.168.3.2: 40.960Mbps 0.025ms 0.024414us/bit 192.168.3.2: 39.385Mbps 0.026ms 0.025391us/bit 192.168.3.2: 44.522Mbps 0.023ms 0.022461us/bit 192.168.3.2: 37.926Mbps 0.027ms 0.026367us/bit --- 192.168.6.246 statistics --- bytes out in dup loss rtt (ms): min avg max std dev 44 54684 54684 0% 0.019 0.021 1.415 0.017 108 54684 54684 0% 0.019 0.020 1.467 0.016 --- 192.168.3.2 statistics --- bytes out in dup loss rtt (ms): min avg max std dev 44 54684 54684 0% 0.089 0.114 35.799 0.300 108 54683 54683 0% 0.116 0.134 23.960 0.216 --- estimated link characteristics --- host bandwidth ms 192.168.3.2 37.926Mbps 0.070
14.37. 删除文件名以"-"开头的文件的方法
因为shell命令参数也是以"-"开头的,所以删除文件名以"-"开头的文件时,要使用以下的命令格式: debian:~# rm -- -foo 或者 debian:~# rm ./-foo
14.38. 利用Windows引导器启动Linux系统
WindowsXP的引导程序也可以引导Linux系统,方法如下: · 在linux系统中用dd命令把linux系统所在分区的头512字节的内容读出来,保存在文件中。 · debian:~# dd if=/dev/hdb1 of=debian.lnx bs=512 count=1 · 把生成的debian.lnx文件拷贝到windows系统分区根目录下,一般就是Windows的C盘。修改C盘根目录下的boot.ini文件,把下面这行内容添加进去。 · c:\debian.lnx="Debian GNU/Linux" · 保存boot.ini文件,重启电脑。在引导菜单中就会出现Debian GNU/Linux的选择项。选择它就可以进入我们的Linux系统了。 |
|