linux常见问题3

By 人生百味 发表于 2006-11-6 22:48:00

查询你的CPU等级
====================================
cat /proc/cpuinfo

如何使用户没有telnet和ftp权限
====================================
若只希望用户没telnet权限,则需要修改/etc/passwd中对应该用户的shell为/bin/true。
若只希望用户没有telnet和ftp权限,则需要修改/etc/passwd中对应该用户的shell为/bin/false。

如何连续执行一个命令
====================================
  使用watch命令,可以反复执行命令,如果和ls配合,可以达到观察某文件大小变化的效果。例如:
  $watch ls -l file.name

如何防止某个关键文件被修改
====================================
  在linux下,有些配置文件是不允许任何人包括root修改的,为了防止被误删除或修改,可以设定该文件的"不可修改位(immutable)"。
  例如:
  chattr +i /etc/fstab
  如果需要修改文件则:
  chattr -i /etc/fstab
  以后再修改文件。

linux环境下如何undelete
====================================
  先在自己的主目录下创建一个名为.trash的子目录,然后在bashrc加入以下指令:
  alias rm 'mv -f !* ~/.trash'
  alias undel 'mv ~/.trash/!* ./!*'
  alias cleantrash '/bin/rm -rf ~/.trash; mkdir ~/.trash;sync'
  alias lrm 'ls ~/.trash'
  若文档是直接用rm命令删除的,理论上 ext2 内 rm 掉的档案还是可以用 debugfs , ext2ed 救回来的.当然... 被 overwrite 掉就没救了。

find  如何找出磁盘中某个大小范围内的文件
find  ====================================
find  比如要查找磁盘中大于3M的文件:
find  find . -size +3000k -exec ls -ld {} ;

如何快速重新执行已经执行过的命令
====================================
  使用!可以实现该功能,例如你前面执行了很多命令,现在突然想执行上一次执行的./configure命令,则只需要输入“!./con”即可而无需使用上下键来滚动查找。
  而!!则能代替前面一个命令。比如刚执行过一次ifconfig,输入“!!”则等于再执行一次ifconfig。
  而且这两个用法可以和其他命令组合,比如你刚执行过ifconfig,然后执行man !!,就等于执行man ifconfig。

当终端出现混乱时,如何让它恢复正常
====================================
  当使用stty命令而出现一些混乱或者更糟的是,使用一个程序而使终端设置完全混乱了时怎么办?要回到“现实”,试试下面的命令:
  stty sane
  如果击键变得混乱时,试着用<CTRL+j>来把命令括起来,输入<CTRL+j>的顺序是先按下CTRL再键入j键。
  <ctrl+j>ctty sane <ctrl+j>
  这个命令不会回到先前的设置,但却可以去除一些稀奇古怪的设置。而真正会出现什么设置要依赖于所使用的系统,但它至少会让你能输入字符,并见到结果。从这里开始,你可以把一些组合键设置为你所喜欢的方式。

tar  如何将.gz文件分割为数个1.44mb
tar  ====================================
tar  把一个文件分割到软盘:
tar  tar cfvm /dev/fd0 file.tar.gz
tar  把软盘上的文件合并到硬盘:
tar  tar xvfm /dev/fd0

如何一次处理一整个目录
====================================
  Linux/UNIX 的很多常用命令如 rm , cp 等都有一个参数---- -r , 是递归的意思, 命令里加了参数 -r 就可以对目标目录及其下所有子目录进行操作,如:
  rm -rf /test (f 是 force 意为强行)
  该命令完全删除根目录下的子目录 test ,作用类似于 dos 下的 deltree ,当然使用这个命令时要特别小心。再如:
  cp -r /test /test1
  有类似 dos 下 xcopy /s 的作用。

redhat下如何允许root通过telnet登录?
====================================
方法1:/etc/securetty ( 加入 pts/0 、pts/1、...)
# echo "pts/0" >> /etc/securetty
方法2:为了在redhat linux系统中激活远程登陆,从文件/etc/pam.d/login中移去下面这一行:
auth required /lib/security/pam_security.so
将/etc/securetty这个文件改名就行啦,该文件是定义root只能在tty1~tty6的终端上登录的,详细的信息可以"man login"。

reboot  Linux正常重新启动的方法有很多种,下面介绍几种常用的重新启动方法:
reboot  ====================================
reboot  Ctrl+Alt+Del
reboot  #init 6
reboot  #shutdown -r now
reboot  #reboot

为什么我的linux不允许普通用户登录?
====================================
  以root的身份登录系统,检查是不是有/etc/nologin这个文件,删除这个文件,然后再以普通用户的身份登录。相信问题已经解决。
  出现这种问题一般是因为系统在关闭的过程中意外中断了操作,如断线或者是插头被拔了之类的意外。而系统在关闭的过程中会自动的产生这个文件,以便通知用户系统正在关闭这就造成普通用户无法登录了。
  另外一种原因是系统管理员在对系统进行维护,为了维护的过程中不受其他用户的影响,需要生成这个文件来禁止其他用户登录。但很不幸系统管理维护完以后忘记删除这个文件了。

chown  如何改变当前路径下所有目录和文件的所有权
chown  ====================================
chown  改变所有子目录及文件的所有权
chown  #chown -R owner[.group] *
chown  也可以用find命令来实现:
chown  #find . -exec chown owner[.group] {} ;

改变所有子目录及文件的属性
在你要改变属性的目录下,输入命令:
#chmod -R 777 *
就可以改变下面所有子目录及文件的属性,不过使用这个命令的时候要特别小心,要是在根目录下打入这个命令,你所有文件的属性都将改变,这就会引起很大的安全性问题。

如何快速查找文件
====================================
  查找文件可以用find,但最好是用locate,速度快,参数少。
  $locate filename
  它是在一个数据库里面查找,所以,要记得经常用updatedb命令更新数据库。一般地,在crontab中的cron.daily脚本会执行/usr/sbin/logrotate /etc/logrotate.conf命令,让机子在每天深夜更新数据库。

如何将Linux或FreeBSD复制到另一颗硬盘 ?
====================================
  Linux上的系统复制很简单,使用cp -ax将partition资料复制过去,重开机後设定lilo就可以了。
  FreeBSD也可以用cp来复制文档,但是对于复制整个文档系统并不是好方法。
  这里介绍使用dump和restore来做:

创建新的文档系统
假如你的新硬盘为ad1, 而将来的根分区将是ad1s1a, 你可以先创建文档系统:
newfs /dev/ad1s1a
mount /dev/ad1s1a /mnt
cd /mnt

复制:
dump -f- / | restore -f- -r
这是把老的根文档系统复制输出到管道,restore从管道里读数据,写入当前目录所在的文档系统。

按部就班复制其他文档系统
复制完後,也许 要修改新硬盘下的/etc/fstab,安装上新的分区,摘下老硬盘就可以了。
再补充一点,如果你要复制的是另外一台机器,可以用rsh,这样就可以通过网络把一个分区数据传送到另外一台机器,不需要NFS,不需SAMBA等就可以解决问题,而cp就很难作到了。
newfs /dev/ad1s1a
mount /dev/ad1s1a /mnt
cd /mnt
rsh -l yourname thathost 'dump -f- /' | restore -f- -r

linux怎么给一个普通用户reboot权限?
====================================
分四种情况讨论:
1.让任何人(包括根本不拥有系统帐号的人)都可以通过控制台reboot
在/etc/inittab文件中保留ca::ctrlaltdel:/sbin/shutdown -t3 -r now
这一行。这样全国人民都可以reboot你的机器,只要你把控制台交出来。

2.让所有系统用户都可以reboot
执行# > /etc/security/console.apps/reboot即可。这就在console.apps目录下生成了一个空文件,文件名就是授权的application。以上路径是针对Mandrake系统而言的,其他系统我不清楚。不过,真正高雅的Mandraker或许根本就不会去靠“>”来生成这个文件??????他们会使用msec来进行控制的。

3.让指定的用户才可以reboot
假设我们要让用户zhizunbao拥有reboot的权限,我们靠uid/gid来完成控制:
# groupadd reboot
# cd /usr/local
# mkdir reboot
# chown root:reboot reboot/
# chmod 750 reboot/
# cd reboot
# cp /sbin/reboot .
# chmod 4755 reboot
# usermod -G reboot zhizunbao


现在,zhizunbao就可以运行/usr/local/reboot/reboot来重启动机器。

4.在一台不设普通用户的机器上启用口令验证reboot
这实际上是靠添加一个关机帐号来实现的,该帐号的shell就是加了s位的/sbin/halt,并且口令只有少数维护人员知道。我们这里采用的就是第4套方案。

怎样知道自己的机器上有哪些服务在运行
====================================
若一台机器运行有很多不需要的服务,那么被攻击者入侵的可能性就会大大加大,因此作为管理员就应该经常查看系统运行有哪些服务。
首先查看系统运行的进程
若需要查看系统当前运行的所有进程,就需要用如下命令:
# ps auxw
其中参数a表示显示系统中所有用户的的进程;u表示输出进程用户所属信息;x表示也显示没有控制台的进程;若显示行太长而被截断则可以使用f参数;
查看系统监听的服务
# netstat -ln
l表示显示当前系统监听的端口信息;n表示端口按照端口号来显示,而不转换为service文件中定义的端口名;若希望了解各个端口都是由哪些进程监听则可以使用p参数。
  若发现不需要的服务,可以使用linuxconf或ntsysv命令来关闭这些服务在系统启动时自启动,然后重新启动系统则这些服务将在运行。
有些服务是由inetd超级服务器来监控的,则需要标记/etc/inetd.conf来关闭这些服务。

查询端口对应的服务
====================================
# lsof -i :端口号
查询此端口对应的服务。

vi 中设置自动缩进
====================================
:set autoindent
:set ai
取消
:set noautoindent
:set noai

如何使linux系统对ping不反应
====================================
  在linux里,如果要想使ping 没反应也就是用来忽略icmp包。可以用:
  echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
  若想恢复就用:
  echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all

如何实现多网卡bondin
====================================
  使用多块网卡虚拟成为一块网卡,具有相同的IP地址。这项技术其实在sun和cisco中已经存在,分别称为Trunking和etherchannel技术,在Linux中,这种技术称为bonding。
  因为bonding在内核2.4.x中已经包含了,只需要在编译的时候把网络设备选项中的Bonding driver support选中就可以了。
  然后,重新编译核心,重新起动计算机,执行如下命令:
  ismod bonding
  ifconfig eth0 down
  ifconfig eth1 down
  ifconfig bond0 ipaddress
  ifenslave bond0 eth0
  ifenslave bond0 eth1
  现在两块网卡已经象一块一样工作了.这样可以提高集群节点间的数据传输.
  你最好把这几句写成一个脚本,再由/etc/rc.d/rc.local调用,以便一开机就生效.
  bonding对于服务器来是个比较好的选择,在没有千兆网卡时,用两三块100兆网卡作bonding,可大大提高服务器到交换机之间的带宽.但是需要在交换机上设置连接bonding网卡的两个口子映射为同一个虚拟接口。

Removing ^M from file
======================================================
if you have transferred a file from MS Windows to UNIX, you might find that the file looks like this:
bleh bleh ^M
leh leh ^M
tey tey tey^M
This is because Windows uses carridge return and newline to indicate a new line.
Here are a number of ways to get rid of the ^M characters:
1- cat filename1 | tr -d "^V^M" > newfile
2- sed -e "s/^V^M//" filename > outputfilename
where ^V is actually control-V and ^M is actually control-M (you must type these yourself, don't just copy and paste this command from this web page)
3-vi solution : open file with vi
1. hit the ESC key
2. :%s/^V^M//
3 - some distributions contain a command called dos2unix which removes these carridge return characters
4- use the texteditor vim (www.vim.org) and edit the file. If all the lines (not only some) contain consistently the carridge return characters then vim will show [textmode] and when you change the mode with the command
:set notextmode
it will remove them.

Create /dev/null
====================================
I have moved a file to /dev/null and now my system doesn't work
If you move a file with the mv command to "/dev/null" then it will be overwritten with an ordinary file.
How to fix it:
Boot your system. If it doesn't boot take a one disk distribution like Toms rtbt and mount your /dev/hdXX partition.
Now type in a shell "mknod /dev/null c 1 3" to create a nod file. /dev/null is the path where the nod file will be saved. The c stands for a character device and the two numbers are the major and the minor numbers for the null device.
After that you must change with "chmod 666 /dev/null" the read, write and execute permissions.
With "ls -alF /dev/" you will see all nod files with it's own three parameters like
"crw-rw-rw- 1 root root 1, 3 Oct 4 11:34 null ".
You will see a "c" in the near of the rwx flags an a " 1, 3" left of the date.

Howto log in to your server passwordless via ssh ( rsa version )
====================================
Create your private and public keys via ssh-keygen program
$ ssh-keygen
Computing keys
Testing the keys..
Key generation complete..
Enter the file in which to save the key (/usr/home/murat/.ssh/identity)
Press enter for the default value...
Your identification has been saved in /usr/home/murat/.ssh/identity
Your public ket is:
blah....blah...blah....
Your public key has been saved in /usr/home/murat/.ssh/identity.pub
Now that we have created our `public` key, take your
public key which is ~/.ssh/identity.pub to your server,
in the ~/.ssh/ directory, create a file named authorized_keys
and append the content of identity.pub file to your authorized_keys file
now, in your machine, type
$ ssh -l username your_remote_machine.domain.com
Boom, no password, no headache, you're in the other side...;)

Blocking anyone to su to root
====================================
The su (Substitute User) command allows you to become other existing
users on the system. For example you can temporarily
become "root" and execute commands as the super-user "root". If
you don't want anyone to su to root or restrict "su" command to
certain users then add the following two lines to the top of
your "su" configuration file in the "/etc/pam.d/" directory.
1- Edit the su file (vi /etc/pam.d/su) and add the following two
lines to the top of the file:
auth sufficient /lib/security/pam_rootok.so debug
auth required /lib/security/pam_wheel.so group=wheel
After adding the two lines above, the "/etc/pam.d/su" file should
look like this:
#%PAM-1.0
auth sufficient /lib/security/pam_rootok.so debug
auth required /lib/security/pam_wheel.so group=wheel
auth required /lib/security/pam_pwdb.so shadow nullok
account required /lib/security/pam_pwdb.so
password required /lib/security/pam_cracklib.so
password required /lib/security/pam_pwdb.so shadow use_authtok nullok
session required /lib/security/pam_pwdb.so
session optional /lib/security/pam_xauth.so
Which means only those who are a member of the "wheel" group can su to root;
and to add a user to wheel group use:
root# usermod -G10 username
Ok, now everybody can not be root using su. When an user that is not in wheel group runs su command ,he/she can not be root even if he/she writes correct root password.

Disable reboot,halt ,shutdown for users
====================================
On Redhat
[root@apache /]# rm -f /etc/security/console.apps/halt
[root@apache /]# rm -f /etc/security/console.apps/poweroff
[root@apache /]# rm -f /etc/security/console.apps/reboot
[root@apache /]# rm -f /etc/security/console.apps/shutdown
[root@apache /]# rm -f /etc/security/console.apps/xserver (if removed, root will be the only user able to start x).

mkdir -p rep1/rep2/rep3 一次建多个目录

rm -rf /tmp/.??* /tmp/* 删除所有文件,包括隐藏文件
You can put this into /etc/rc.d/init.d/syslog into the "stop)" section. This will clean up /tmp at every shutdown and keep your disk tidy.
Do not run the above command while running X11 or before you run startx. X11 needs the /tmp/.font-unix which is created by xfont server and X11 it self creates the directory /tmp/.X11-unix which is needed to talk to the X11 windows.

 

1、BIOS的安全设置

  这是最基本的了,也是最简单的了。一定要给你的BIOS设置密码,以防止通过在BIOS中改变启动顺序,而可以从软盘启动。这样可以阻止别有用心的试图用特殊的启动盘启动你的系统,还可以阻止别人进入BIOS改动其中的设置,使机器的硬件设置不能被别人随意改动。

  2、LILO的安全设置

  LILO是LInux

  LOader的缩写,它是LINUX的启动模块。可以通过修改“/etc/lilo.conf”文件中的内容来进行配置。在 /etc/lilo.conf文件中加如下面两个参数:restricted,password。这三个参数可以使你的系统在启动lilo时就要求密码验证。

  第一步:编辑lilo.conf文件(vi /etc/lilo.comf),假如或改变这三个参数:
  boot=/dev/hda
  map=/boot/map
  install=/boot/boot.b
  prompt
  timeout=00 #把这行该为00,这样系统启动时将不在等待,而直接启动LINUX
  message=/boot/message
  linear
  default=linux
  restricted #加入这行
  password= #加入这行并设置自己的密码

  image=/boot/vmlinuz-2.4.2-2
  label=linux
  root=/dev/hda6
  read-only

  第二步:因为"/etc/lilo.conf"文件中包含明文密码,所以要把它设置为root权限读取。
  # chmod 0600 /etc/lilo.conf

  第三步:更新系统,以便对“/etc/lilo.conf”文件做的修改起作用。
  # /sbin/lilo -v

  第四步:使用“chattr”命令使"/etc/lilo.conf"文件变为不可改变。
  # chattr +i /etc/lilo.conf

  这样可以在一定程度上防止对“/etc/lilo.conf”任何改变(意外或其他原因)

  3、让口令更加安全

  口令可以说是系统的第一道防线,目前网上的大部分对系统的攻击都是从截获口令或者猜测口令开始的,所以我们应该选择更加安全的口令。


  首先要杜绝不设口令的帐号存在。这可以通过查看/etc/passwd文件发现。例如,存在的用户名为test的帐号,没有设置口令,则在/etc/passwd文件中就有如下一行:
  test::100:9::/home/test:/bin/bash

  其第二项为空,说明test这个帐号没有设置口令,这是非常危险的!应将该类帐号删除或者设置口令。
其次,在旧版本的linux中,在/etc/passwd文件中是包含有加密的密码的,这就给系统的安全性带来了很大的隐患,最简单的方法就是可以用暴力破解的方法来获得口令。可以使用命令/usr/sbin/pwconv或者/usr/sbin/grpconv来建立/etc/shadow或者 /etc/gshadow文件,这样在/etc/passwd文件中不再包含加密的密码,而是放在/etc/shadow文件中,该文件只有超级用户 root可读!

  第三点是修改一些系统帐号的Shell变量,例如uucp,ftp和news等,还有一些仅仅需要FTP功能的帐号,一定不要给他们设置/bin/bash或者/bin/sh等Shell变量。可以在/etc/passwd中将它们的Shell变量置空,例如设为 /bin/false或者/dev/null等,也可以使用usermod -s /dev/null username命令来更改username的 Shell为/dev/null。这样使用这些帐号将无法Telnet远程登录到系统中来!

  第四点是修改缺省的密码长度:在你安装linux时默认的密码长度是5个字节。但这并不够,要把它设为8。修改最短密码长度需要编辑login.defs文件(vi/etc/login.defs),把下面这行
  PASS_MIN_LEN 5
  改为
  PASS_MIN_LEN 8
  login.defs文件是login程序的配置文件。

  4、自动注销帐号的登录


  在unix系统中root账户是具有最高特权的。如果系统管理员在离开系统之前忘记注销root账户,那将会带来很大的安全隐患,应该让系统会自动注销。通过修改账户中“TMOUT”参数,可以实现此功能。TMOUT按秒计算。编辑你的profile文件(vi /etc/profile),在 "HISTFILESIZE="后面加入下面这行:
  TMOUT=300

  300,表示300秒,也就是表示5分钟。这样,如果系统中登陆的用户在5分钟内都没有动作,那么系统会自动注销这个账户。你可以在个别用户的“.bashrc”文件中添加该值,以便系统对该用户实行特殊的自动注销时间。

  改变这项设置后,必须先注销用户,再用该用户登陆才能激活这个功能。

  5、取消普通用户的控制台访问权限

  你应该取消普通用户的控制台访问权限,比如shutdown、reboot、halt等命令。
  # rm -f /etc/security/console.apps/
  是你要注销的程序名。

  6、取消并反安装所有不用的服务

  取消并反安装所有不用的服务,这样你的担心就会少很多。察看“/etc/inetd.conf”文件,通过注释取消所有你不需要的服务(在该服务项目之前加一个“#”)。然后用“sighup”命令升级“inetd.conf”文件。

  第一步:

  更改“/etc/inetd.conf”权限为600,只允许root来读写该文件。
  # chmod 600 /etc/inetd.conf

  第二步:

  确定“/etc/inetd.conf”文件所有者为root。

  第三步:

  编辑 /etc/inetd.conf文件(vi /etc/inetd.conf),取消下列服务(你不需要的):ftp, telnet,  shell, login, exec, talk, ntalk, imap, pop-2, pop-3, finger, auth等等。把不需要的服务关闭可以使系统的危险性降低很多。


  第四步:

  给inetd进程发送一个HUP信号:
  # killall -HUP inetd

  第五步:

  用chattr命令把/ec/inetd.conf文件设为不可修改,这样就没人可以修改它:
  # chattr +i /etc/inetd.conf

   这样可以防止对inetd.conf的任何修改(以外或其他原因)。唯一可以取消这个属性的人只有root。如果要修改inetd.conf文件,首先要是取消不可修改性质:
  # chattr -i /etc/inetd.conf

  别忘了该后再把它的性质改为不可修改的。

  7、TCP_WRAPPERS

  使用TCP_WRAPPERS可以使你的系统安全面对外部入侵。最好的策略就是阻止所有的主机("/etc/hosts.deny"文件中加入 "ALL: ALL@ALL, PARANOID" ),然后再在"/etc/hosts.allow" 文件中加入所有允许访问的主机列表。

  第一步:

  编辑hosts.deny文件(vi /etc/hosts.deny),加入下面这行
  # Deny access to everyone.
  ALL: ALL@ALL, PARANOID

  这表明除非该地址包在允许访问的主机列表中,否则阻塞所有的服务和地址。

  第二步:

  编辑hosts.allow文件(vi /etc/hosts.allow),加入允许访问的主机列表,比如:
  ftp: 202.54.15.99 foo.com
  202.54.15.99和 foo.com是允许访问ftp服务的ip地址和主机名称。

  第三步:

  tcpdchk程序是tepd wrapper设置检查程序。它用来检查你的tcp wrapper设置,并报告发现的潜在的和真实的问题。设置完后,运行下面这个命令:
  # tcpdchk

  8、修改“/etc/host.conf”文件

  “/etc/host.conf”说明了如何解析地址。编辑“/etc/host.conf”文件(vi /etc/host.conf),加入下面这行:
  # Lookup names via DNS first then fall back to /etc/hosts.
  order bind,hosts
  # We have machines with multiple IP addresses.
  multi on
  # Check for IP address spoofing.
  nospoof on

  第一项设置首先通过DNS解析IP地址,然后通过hosts文件解析。第二项设置检测是否“/etc/hosts”文件中的主机是否拥有多个IP地址(比如有多个以太口网卡)。第三项设置说明要注意对本机未经许可的电子欺骗。

  9、使“/etc/services”文件免疫

  使“/etc/services”文件免疫,防止未经许可的删除或添加服务:
  # chattr +i /etc/services

  10、不允许从不同的控制台进行root登陆

  "/etc/securetty"文件允许你定义root用户可以从那个TTY设备登陆。你可以编辑"/etc/securetty"文件,再不需要登陆的TTY设备前添加“#”标志,来禁止从该TTY设备进行root登陆。

  在/etc/inittab文件中有如下一段话:
  # Run gettys in standard runlevels
  1:2345:respawn:/sbin/mingetty tty1
  2:2345:respawn:/sbin/mingetty tty2
  #3:2345:respawn:/sbin/mingetty tty3
  #4:2345:respawn:/sbin/mingetty tty4
  #5:2345:respawn:/sbin/mingetty tty5
  #6:2345:respawn:/sbin/mingetty tty6

  系统默认的可以使用6个控制台,即Alt+F1,Alt+F2...,这里在3,4,5,6前面加上“#”,注释该句话,这样现在只有两个控制台可供使用,最好保留两个。然后重新启动init进程,改动即可生效!

  11、使用PAM(可插拔认证模块)禁止任何人通过su命令改变为root用户su(Substitute

  User替代用户)命令允许你成为系统中其他已存在的用户。如果你不希望任何人通过su命令改变为root用户或对某些用户限制使用su命令,你可以在su配置文件(在"/etc/pam.d/"目录下)的开头添加下面两行:
编辑su文件(vi /etc/pam.d/su),在开头添加下面两行:
  auth sufficient /lib/security/pam_rootok.so
  auth required /lib/security/Pam_wheel.so group=wheel

  这表明只有"wheel"组的成员可以使用su命令成为root用户。你可以把用户添加到“wheel”组,以使它可以使用su命令成为root用户。添加方法可以用这个命令:chmod -G10 username 。

  12、Shell logging Bash

  shell在“~/.bash_history”(“~/”表示用户目录)文件中保存了500条使用过的命令,这样可以使你输入使用过的长命令变得容易。每个在系统中拥有账号的用户在他的目录下都有一个“.bash_history”文件。bash
shell应该保存少量的命令,并且在每次用户注销时都把这些历史命令删除。

  第一步:

  “/etc/profile”文件中的“HISTFILESIZE”和“HISTSIZE”行确定所有用户的“.bash_history”文件中可以保存的旧命令条数。强烈建议把把“/etc/profile”文件中的“HISTFILESIZE”和“HISTSIZE”行的值设为一个较小的数,比如 30。编辑profile文件(vi/etc/profile),把下面这行改为:
  HISTFILESIZE=30
  HISTSIZE=30

  这表示每个用户的“.bash_history”文件只可以保存30条旧命令。

  第二步:


  网管还应该在"/etc/skel/.bash_logout" 文件中添加下面这行"rm -f $HOME/.bash_history" 。这样,当用户每次注销时,“.bash_history”文件都会被删除。

  编辑.bash_logout文件(vi /etc/skel/.bash_logout) ,添加下面这行:
  rm -f $HOME/.bash_history

  13、禁止Control-Alt-Delete键盘关闭命令

  在"/etc/inittab" 文件中注释掉下面这行(使用#):
  ca::ctrlaltdel:/sbin/shutdown -t3 -r now
  改为:
  #ca::ctrlaltdel:/sbin/shutdown -t3 -r now

  为了使这项改动起作用,输入下面这个命令:
  # /sbin/init q

  14、给"/etc/rc.d/init.d" 下script文件设置权限

  给执行或关闭启动时执行的程序的script文件设置权限。
  # chmod -R 700 /etc/rc.d/init.d/*

  这表示只有root才允许读、写、执行该目录下的script文件。

  15、隐藏系统信息

  在缺省情况下,当你登陆到linux系统,它会告诉你该linux发行版的名称、版本、内核版本、服务器的名称。对于黑客来说这些信息足够它入侵你的系统了。你应该只给它显示一个“login:”提示符。

  首先编辑"/etc/rc.d/rc.local" 文件,在下面显示的这些行前加一个“#”,把输出信息的命令注释掉。
  # This will overwrite /etc/issue at every boot. So, make any changes you
  # want to make to /etc/issue here or you will lose them when you reboot.
  #e cho "" > /etc/issue
  #e cho "$R" >> /etc/issue

 

 #e cho "Kernel $(uname -r) on $a $(uname -m)" >> /etc/issue
  #
  #cp -f /etc/issue /etc/issue.net
  #e cho >> /etc/issue

  其次删除"/etc"目录下的“isue.net”和"issue"文件:
  # rm -f /etc/issue
  # rm -f /etc/issue.net

  16、禁止不使用的SUID/SGID程序

  如果一个程序被设置成了SUID

  root,那么普通用户就可以以root身份来运行这个程序。网管应尽可能的少使用SUID/SGID 程序,禁止所有不必要的SUID/SGID程序。

  查找root-owned程序中使用's'位的程序:
  # find / -type f ( -perm -04000 -o -perm -02000 ) -exec ls -lg {} /;

  用下面命令禁止选中的带有's'位的程序:
  # chmod a-s [program]

 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值