寻觅生命中的那一片浅草......

发布者 夜行人

ssh+chroot+jailit锁定普通用户活动目录

原文链接:http://bbs.linuxtone.org/thread-2937-1-1.html IT运维专家网–“自由平等,互助分享!”

http://olivier.sessink.nl/jailkit/jailkit-2.0.tar.gz
tar -zxvf jailkit-2.0.tar.gz
cd jailkit-2.0
./configure
make
make install
mkdir /jail
chown root:root /jail

jk_init -v /jail basicshell
jk_init -v /jail editors
jk_init -v /jail extendedshell
jk_init -v /jail netutils
jk_init -v /jail ssh
jk_init -v /jail sftp

adduser thomas

jk_jailuser -m -j /jail thomas

vi /etc/passwd:
thomas:x:1001:500::/jail/./home/thomas:/usr/sbin/jk_chrootsh

passwd thomas

mkdir -p /jail/home/thomas

chown thomas:thomas /jail/home/thomas

vi /jail/etc/group
paste and save this:
thomas:x:500:

vi /jail/etc/passwd
paste and save this:
thomas:x:1001:500::/home/thomas:/bin/bash

cp /etc/skel/.bashrc /jail/home/thomas
chown thomas:thomas /jail/home/thomas/.bashrc
ssh thomas@localhost

千万不要死套用,这只是我配置成功的过程,可能某些地方和大家有点差别要灵活运用

现在已经出到2.11版了,我自己的安装过程
以下是它安装的一些文件
/usr/bin/install -c -d -m 755 /usr
/usr/bin/install -c -d -m 755 /usr/bin
/usr/bin/install -c -d -m 755 /usr/sbin
/usr/bin/install -c -m 0755 jk_socketd /usr/sbin/
/usr/bin/install -c -m 0755 jk_chrootlaunch /usr/sbin/
/usr/bin/install -c -m 0755 jk_lsh /usr/sbin/
/usr/bin/install -c -m 4755 jk_chrootsh /usr/sbin/
/usr/bin/install -c -m 4755 jk_uchroot /usr/bin/

在执行
jk_jailuser -m -j /jail thomas
时,会提示找不到命令,我们手动复制过去

mkdir /jail/usr/sbin
cd /jail/usr/sbin
/bin/cp -a /usr/sbin/* .

另外/jail/etc/passwd中
thomas:x:504:505::/home/thomas:/usr/sbin/jk_lsh
默认的shell是/usr/sbin/jk_lsh,当设置为这个时,登录会提示/usr/sbin/jk_lsh: error while loading shared libraries: libcap.so.1: cannot open shared object file: No such file or directory

后来把/usr/sbin/jk_lsh修改为/bin/bash则可以正常登录

统计几个目录大小的sh

#!/bin/bash
#目录名类似于20100315,20100315long,20100316,20100316zhong,20100317等
#用法 sh count_dir_size.sh 日期最小数,日期最大数
#如果是2010-03-15到2010-03-17,则sh count_dir_size.sh 2010-03-15 2010-03-17
#Author johncan,2010-03-22
#COUNT_DATE=`date “+%Y%m%d” |cut -c1-5`
if [ -z “$1” ]
then
echo “please use $0 start_day end_day”
exit 1
fi

#将开始时间转换成时间戳
STA_TIME=`date -d “$1” +%s`
#将结束时间转换成时间戳
END_TIME=`date -d “$2” +%s`

cd /dir_which_files_are_stored

DR_TIME=${STA_TIME}
while [ “${DR_TIME}” -le “${END_TIME}” ]
do
#将时间戳转换为目录名的格式
STAND_DR_TIME=`date -d “1970-01-01 UTC ${DR_TIME} seconds” +%Y%m%d`
for DR in ${STAND_DR_TIME}*
do
#统计目录大小
DR_SIZE=`du -s ${DR} | awk ‘{print $1}’`
let “COUNT_DR_SIZE=${COUNT_DR_SIZE}+${DR_SIZE}”
done
let “DR_TIME=${DR_TIME}+86400”
done
echo ${COUNT_DR_SIZE}KB

禁止通过IP访问Jboss

cd /your_install_dir/jbossweb-tomcat50.sar/
/bin/cp server.xml server.xml.100323
vi server.xml

先修改默认的8080端口

<Service name=”jboss.web”
className=”org.jboss.web.tomcat.tc5.StandardService”>

<!– A HTTP/1.1 Connector on port 8080 –>
<!– The compression parameters are taken from the default Tomcat server.xml–>
<Connector port=”8080″ address=”${jboss.bind.address}”

将port=”8080″修改为port=”8888″

禁止通过IP访问,只允许通过域名访问

在<Host name=”localhost”
autoDeploy=”false” deployOnStartup=”false” deployXML=”false”>
前添加一个IP命名的virtual host

假如服务器IP是192.168.0.100,则添加的host如下

<Host name=”192.168.0.100″>
<Valve className=”org.apache.catalina.valves.RemoteAddrValve” deny=”0.0.0.0″/>
</Host>

现在启动Jboss,就不能通过IP访问了,只能通过域名,但任何解析到192.168.0.100的域名都可以访问
有机会再研究下只绑定一个域名的情况

参考:http://xuliangyong.javaeye.com/blog/410148

shell字符串的截取

shell字符串的截取的问题:
一、Linux shell 截取字符变量的前8位,有方法如下:
1.expr substr “$a” 1 8
2.echo $a|awk ‘{print substr(,1,8)}’
3.echo $a|cut -c1-8
4.echo $
5.expr $a : ‘\(.\\).*’
6.echo $a|dd bs=1 count=8 2>/dev/null

二、按指定的字符串截取
1、第一种方法:
${varible##*string} 从左向右截取最后一个string后的字符串
${varible#*string}从左向右截取第一个string后的字符串
${varible%%string*}从右向左截取最后一个string后的字符串
${varible%string*}从右向左截取第一个string后的字符串
“*”只是一个通配符可以不要

例子:
$ MYVAR=foodforthought.jpg
$ echo ${MYVAR##*fo}
rthought.jpg
$ echo ${MYVAR#*fo}
odforthought.jpg

2、第二种方法:${varible:n1:n2}:截取变量varible从n1到n2之间的字符串。

可以根据特定字符偏移和长度,使用另一种形式的变量扩展,来选择特定子字符串。试着在 bash 中输入以下行:
$ EXCLAIM=cowabunga
$ echo ${EXCLAIM:0:3}
cow
$ echo ${EXCLAIM:3:7}
abunga

这种形式的字符串截断非常简便,只需用冒号分开来指定起始字符和子字符串长度。

三、按照指定要求分割:
比如获取后缀名
ls -al | cut -d “.” -f2
转载自:http://tech.foolpig.com/2008/07/09/linux-shell-char/

Boot_centos5.3_into_single_user_mode_on_XenServer

Today,I clone a VM in the XenCenter.I want to log into the new VM to configure ip and so on,But I had forgotten the original VM’s root password.So I can not log into the new one.

There are at least two kinds of way to reset the root password.One way is making the new VM boot from cdrom. I think it is too complicated to do that.The other way is editing grub’s boot option and making the VM boot into single user mode.It’s easy to do that.Follow this step:choose the new VM–>Shut down the new VM–>click the right mouse button–>Properties–>Startup Options–>OS Boot Parameters–>add single after utf8,the conten after edited is graphical utf8 single.Start the new VM again,it boot into single user mode,now we can change root password.

At last,shut down the VM,change OS Boot Parameters’s content to graphical utf8,start the new VM.

2026年三月
« 5月    
 1
2345678
9101112131415
16171819202122
23242526272829
3031