- 论坛徽章:
- 0
|
现在,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、让口令更加安全
口令可以说是系统的第一道防线,目前网上的大部分对系统的攻击都是从截获口令或者猜测口令开始的,所以我们应该选择更加安全的口令。 |
|