linux 技巧集
时间:2005-10-03 20:36:59 来源:站长资讯收集整理 作者:佚名
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网卡的两个口子映射为同一个虚拟接口。
Mounting ISO images (no CD-R required)
by Adrian Chung
======================================
You've just downloaded a 650MB ISO file, ready for burning to a CD-R. The MD5 hash checks out, but you're still not sure if the image contains what you want. If you're too impatient to wait for the CD-R to burn, you can browse the actual downloaded file via the loopback device. First create a mount point
bash# mkdir /mnt/iso
Then mount the .iso file:
bash# mount -t iso9660 -o loop Mandrake80-inst.iso /mnt/iso
Now browse the directory tree mounted on /mnt/iso. This is useful as a space saving measure when you want access to both the directory tree and to the raw .iso image on the same machine.
Removing ^M from file
by Ismail YENIGUL , homepage: http://www.enderunix.org
======================================================
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
by Mariusz Zinowicz
====================================
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.
Resetting your terminal/shell window
by Buffer_7
====================================
When accidentally doing a :
cat /bin/somefile_binary
you can end up with a "broken terminal". The binary file may possibly contain characters that
put a terminal into a mode where the output becomes unreadable. To put the terminal back to
normal you can type blindly:
reset
and it's normal.
best regards
Howto log in to your server passwordless via ssh ( rsa version )
by Murat Ilker Balaban , homepage: http://www.enderunix.org/
====================================
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
by Ismail YENIGUL , homepage: http://apache.cslab.itu.edu.tr
====================================
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
by Ismail YENIGUL , homepage: http://apache.cslab.itu.edu.tr
====================================
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).
How to create many subdirectories in one time
by Pascal Mulier
====================================
Sometimes, we want to create 2 or 3 (or more) directories at the same time.
For example, you are in "rep1" directory ("rep1" doesn't contain any subdirectory) and want to create rep1/rep2/rep3
With "p" option of the mkdir command , it's very easy :
mkdir -p rep1/rep2/rep3
How to delete all files from /tmp?
====================================
Simple question? Well, how do you delete files in directories that start with a dot in the name?
Rm -r /tmp/.* WILL DELETE THE WHOLE DISK as it selects also the file /tmp/.. Therefore never try this. The solution is to add two question marks before the '*'-wildcard:
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.
上一篇:详述Linux平台下的安全性


















文章评论
共有 位CH网友发表了评论 查看完整内容