Anda di halaman 1dari 12

How to redirect all users to particular directory fallow the fallowing steps do that

All the users belonging to ftp-users group goes into /home/ftp-docs/ftp_stuff by default when
they login. They cannot navigate in other directories and are restricted to this particular
directory.
You do this:
Create a directory by issuing the following command as root:
mdir -p /home/ftp-docs/ftp_stuff
Then do this:-
chgrp ftp-users /home/ftp-docs/ftp_stuff
chmod !""" /home/ftp-docs/ftp_stuff
#n the /etc/vsftpd/vsftpd.conf write this
chroot_list_enable$Y%&
chroot_list_file$/etc/vsftpd.chroot_list
'ut all you ftp-users group user( name in /etc/vsftpd.chroot_list
Then in the /etc/passwd file mae the home directory of all the users belonging to ftp-users
group to /home/ftp-docs/ftp_stuff.
Then do the following:
service vsftpd restart
Then login via any user belonging to ftp-users group you will lend into /home/ftp-docs/ftp_stuff.
You cant go to the other higher level directories.
)hen you will issue this
ftp * pwd
You will get to see this
+/+
,on-t bother this.
You will remain in /home/ftp-docs/ftp_stuff only. You can chec that out by
doing ls.
How to create CHROOT for ssh service
Creating a Chroot Jail for SSH Access
I wanted to setup a way to allow SSH access to my machine but limit their abilities heavily. To
do that I figured a chroot jail was the best way. In this example I'm using Archinux and
!penSSH ".#p#. It should be a very similar process on any $nix operating system.
Setup your test user
The way I'm setting this up% is that all my chrooted users will be added to the sshusers group. So
we must setup the group% then add the user.
$ groupadd sshusers
$ adduser -g sshusers user
Setup the jail directories
The next step is to setup all the directories needed. This needs to emulate the & directory to a bare
minimum. That is we need a dev% etc% lib% usr% and bin directory as well as usr&bin&. The base
directory has to be owned by root.
$ mkdir -p /var/jail/{dev,etc,lib,usr,bin}
$ mkdir -p /var/jail/usr/bin
$ chown root.root /var/jail
'ou also need the &dev&null file(
$ mknod -m 666 /var/jail/dev/null c 1
'ou need to fill up the etc directory with a few minimum files(
$ cd /var/jail/etc
$ cp /etc/ld.so.cache .
$ cp /etc/ld.so.con! .
$ cp /etc/nsswitch.con! .
$ cp /etc/hosts .
!nce this is done you need to figure out what commands you want accessible by your limited
users. In this example I only want the users to be able to get into bash and use the ls command.
So you must copy the binaries to the jail.
$ cd /var/jail/usr/bin
$ cp /usr/bin/ls .
$ cp /usr/bin/bash .
)ow that you've got all the binaries in place% you need to add the proper shared libraries. To find
out what libraries are need you can run ldd &path&to&bin. The output loo*s similar to this(
$ ldd /bin/ls
linu"-gate.so.1 #$ %&"b'!(b&&&)
librt.so.1 #$ /lib/librt.so.1 %&"b'!1d&&&)
libacl.so.1 #$ /lib/libacl.so.1 %&"b'!16&&&)
libc.so.6 #$ /lib/libc.so.6 %&"b'dc!&&&)
libpthread.so.& #$ /lib/libpthread.so.& %&"b'db'&&&)
/lib/ld-linu".so.( %&"b'!(c&&&)
libattr.so.1 #$ /lib/libattr.so.1 %&"b'db(&&&)
Then you have to manually copy each file to the lib directory in your jail. That is a pain.
+specially if there is a lot of shared libraries for a binary you want. I came across a useful script
called l,chroot which automatically finds the libraries and copies them to your chroot jail.
cd /sbin
wget -* l(chroot http+//www.c,berciti.bi-/!iles/lighttpd/l(chroot.t"t
chmod ." l(chroot
+dit the l,chroot file and change BASE=/webroot to BASE=/var/jail. This tells l,chroot
where your jail is located so it copies everything to the right place. )ow go ahead and run the
command on the binaries you want.
l(chroot ls
l(chroot bash
Configure SSHd to Chroot your users
All that is left is to set a few things in your sshd configuration file. 'ou need to ma*e sure you
have at least !penSSH -..p#% because before that they didn't have this nice /hroot0irectory12
function. 3reviously there was a few extra steps you had to ta*e to get it wor*ing% but really you
should have a newer version anyway. To configure /hroot0irectory add the following to
&etc&ssh&sshd4config(
/atch group sshusers
0hroot1irector, /var/jail/
2113orwarding no
4llow5cp3orwarding no
)ote that this also disables 5##6orwarding and does not allow port forwarding. If you want to
setup a box to allow secure tunneling for your friends% you may want to change this.
Optional Steps
7hen you login to your test user% you'll notice a prompt as such(
bash--($
That is not a very useful bash prompt. So if you want something a little better I recommend
simply copying the contents of &etc&s*el to &var&jail&home&user. This gives you a .bashrc file
which sets the 3S# variable to a much nicer loo*ing prompt. Here's what mine loo*s li*e(
phr,gian+6$ echo $781
9h+9w$
phr,gian+6$
SHELL SCRIPTIN E!"#PLES
../. 0ow to write shell script that will add two nos1 which are supplied as command line
argument1 and if this two nos are not given show error and its usage
:;/bin/bash
:
: <inu" 8hell 8cripting 5utorial 1.&=r, 8ummer-(&&(
:
: >ritten b, ?ivek @. @ite AvivekBni"cra!t.com$
:
: <atest version can be !ound at http+//www.ni"cra!t.com/
:
: C1.8cript to sum to nos
:
i! D $: -ne ( E
then
echo FGsage - $& " ,F
echo F >here " and , are two nos !or which H will print sumF
e"it 1
!i
echo F8um o! $1 and $( is Ie"pr $1 . $(IF
:
: ./ch.sh+ vivek-tech.com to ni"cra!t.com re!erance converted using this tool
: 8ee the tool at http+//www.ni"cra!t.com/uniJlinu"!eatures/tools/
:
..2.)rite &cript to find out biggest number from given three nos. 3os are supplies as command
line argument. 'rint error if sufficient arguments are not supplied.
:;/bin/bash
:
: <inu" 8hell 8cripting 5utorial 1.&=r, 8ummer-(&&(
:
: >ritten b, ?ivek @. @ite AvivekBni"cra!t.com$
:
: <atest version can be !ound at http+//www.ni"cra!t.com/
:
: C(. 8cript to !ind out bigest number
:
: 4lgo+
: 1) 854K5+ 5ake three nos as n1,n(,n.
: () Hs n1 is greater than n( and n, i! ,es
: print n1 is bigest no goto step =, otherwise goto ne"t step
: ) Hs n( is greater than n1 and n, i! ,es
: print n( is bigest no goto step =, otherwise goto ne"t step
: L) Hs n is greater than n1 and n(, i! ,es
: print n is bigest no goto step =, otherwise goto ne"t step
: =) MN1
:
:
i! D $: -ne E
then
echo F$&+ number1 number( number are not givenF $O(
e"it 1
!i
n1#$1
n(#$(
n#$
i! D $n1 -gt $n( E OO D $n1 -gt $n E
then
echo F$n1 is Pigest numberF
eli! D $n( -gt $n1 E OO D $n( -gt $n E
then
echo F$n( is Pigest numberF
eli! D $n -gt $n1 E OO D $n -gt $n( E
then
echo F$n is Pigest numberF
eli! D $1 -eJ $( E OO D $1 -eJ $ E OO D $( -eJ $ E
then
echo F4ll the three numbers are eJualF
else
echo FH can not !igure out which number is bigerF
!i
:
: ./ch.sh+ vivek-tech.com to ni"cra!t.com re!erance converted using this tool
: 8ee the tool at http+//www.ni"cra!t.com/uniJlinu"!eatures/tools/
:
..!.)rite script to print nos as 4151!121/ using while loop.
:;/bin/bash
:
: <inu" 8hell 8cripting 5utorial 1.&=r, 8ummer-(&&(
:
: >ritten b, ?ivek @. @ite AvivekBni"cra!t.com$
:
: <atest version can be !ound at http+//www.ni"cra!t.com/
:
: C
: 4lgo+
: 1) 854K5+ set value o! i to = %since we want to start !rom =, i! ,ou
: want to start !rom other value put that value)
: () 8tart >hile <oop
: ) 0hechk, Hs value o! i is -ero, H! ,es goto step = else
: continue with ne"t step
: L) print i, decement i b, 1 %i.e. i#i-1 to goto -ero) and
: goto step
: =) MN1
:
i#=
while test $i ;# &
do
echo F$i
F
i#Ie"pr $i - 1I
done
:
: ./ch.sh+ vivek-tech.com to ni"cra!t.com re!erance converted using this tool
: 8ee the tool at http+//www.ni"cra!t.com/uniJlinu"!eatures/tools/
:
..5. )rite &cript1 using case statement to perform basic math operation as
follows
6 addition
- subtraction
7 multiplication
/ division
The name of script must be -85- which wors as follows
9 ./85 2: / !1 Also chec for sufficient command line arguments
:;/bin/bash
:
: <inu" 8hell 8cripting 5utorial 1.&=r, 8ummer-(&&(
:
: >ritten b, ?ivek @. @ite AvivekBni"cra!t.com$
:
: <atest version can be !ound at http+//www.ni"cra!t.com/
:
: CL
:
i! test $: #
then
case $( in
.) let -#$1.$QQ
-) let -#$1-$QQ
/) let -#$1/$QQ
"R2) let -#$1S$QQ
S) echo >arning - $( invalied operator, onl, .,-,",/ operator allowed
e"itQQ
esac
echo 4nswer is $-
else
echo FGsage - $& value1 operator value(F
echo F >here, value1 and value( are numeric valuesF
echo F operator can be .,-,/," %3or /ultiplication)F
!i
:
: ./ch.sh+ vivek-tech.com to ni"cra!t.com re!erance converted using this tool
: 8ee the tool at http+//www.ni"cra!t.com/uniJlinu"!eatures/tools/
:
..;.)rite script to print given number in reverse order1 for eg. #f no is /2! it must print as !2/.
:;/bin/bash
:
: <inu" 8hell 8cripting 5utorial 1.&=r, 8ummer-(&&(
:
: >ritten b, ?ivek @. @ite AvivekBni"cra!t.com$
:
: <atest version can be !ound at http+//www.ni"cra!t.com/
:
: 8cript to reverse given no
:
: 4lgo+
: 1) Hnput number n
: () 8et rev#&, sd#&
: ) 3ind single digit in sd as n T 1& it will give %le!t most digit)
: L) 0onstruct revrse no as rev S 1& . sd
: =) 1ecrment n b, 1
: 6) Hs n is greater than -ero, i! ,es goto step , otherwise ne"t step
: ') 7rint rev
:
i! D $: -ne 1 E
then
echo FGsage+ $& numberF
echo F H will !ind reverse o! given numberF
echo F 3or eg. $& 1(, H will print (1F
e"it 1
!i
n#$1
rev#&
sd#&
while D $n -gt & E
do
sd#Ie"pr $n T 1&I
rev#Ie"pr $rev 9S 1& . $sdI
n#Ie"pr $n / 1&I
done
echo FKeverse number is $revF
:
: ./ch.sh+ vivek-tech.com to ni"cra!t.com re!erance converted using this tool
: 8ee the tool at http+//www.ni"cra!t.com/uniJlinu"!eatures/tools/
:
..4.)rite &cript to see current date1 time1 username1 and current directory
:;/bin/bash
:
: <inu" 8hell 8cripting 5utorial 1.&=r, 8ummer-(&&(
:
: >ritten b, ?ivek @. @ite AvivekBni"cra!t.com$
:
: <atest version can be !ound at http+//www.ni"cra!t.com/
:
: C=
:
echo FUello, $<*@N4/MF
echo F0urrent date is IdateIF
echo FGser is Iwho i amIF
echo F0urrent direcotr, IpwdIF
:
: ./ch.sh+ vivek-tech.com to ni"cra!t.com re!erance converted using this tool
: 8ee the tool at http+//www.ni"cra!t.com/uniJlinu"!eatures/tools/
:
..".)rite script to print given numbers sum of all digit1 <or eg. #f no is /2! it-s sum of all digit will
be /626! $ ;.
:;/bin/bash
:
: <inu" 8hell 8cripting 5utorial 1.&=r, 8ummer-(&&(
:
: >ritten b, ?ivek @. @ite AvivekBni"cra!t.com$
:
: <atest version can be !ound at http+//www.ni"cra!t.com/
:
: 4lgo+
: 1) Hnput number n
: () 8et sum#&, sd#&
: ) 3ind single digit in sd as n T 1& it will give %le!t most digit)
: L) 0onstruct sum no as sum#sum.sd
: =) 1ecrment n b, 1
: 6) Hs n is greater than -ero, i! ,es goto step , otherwise ne"t step
: ') 7rint sum
:
i! D $: -ne 1 E
then
echo FGsage+ $& numberF
echo F H will !ind sum o! all digit !or given numberF
echo F 3or eg. $& 1(, H will print 6 as sum o! all digit %1.(.)F
e"it 1
!i
n#$1
sum#&
sd#&
while D $n -gt & E
do
sd#Ie"pr $n T 1&I
sum#Ie"pr $sum . $sdI
n#Ie"pr $n / 1&I
done
echo F8um o! digit !or numner is $sumF

:
: ./ch.sh+ vivek-tech.com to ni"cra!t.com re!erance converted using this tool
: 8ee the tool at http+//www.ni"cra!t.com/uniJlinu"!eatures/tools/
:
../:.0ow to perform real number calculation in shell script and store result to
third variable 1 lets say a$4.;;1 b$=.;"1 c$a6b>
:;/bin/bash
:
: <inu" 8hell 8cripting 5utorial 1.&=r, 8ummer-(&&(
:
: >ritten b, ?ivek @. @ite AvivekBni"cra!t.com$
:
: <atest version can be !ound at http+//www.ni"cra!t.com/
:
: C1&
:
a#=.66
b#V.6'
c#Iecho $a . $b R bcI
echo F$a . $b # $cF
:
: ./ch.sh+ vivek-tech.com to ni"cra!t.com re!erance converted using this tool
: 8ee the tool at http+//www.ni"cra!t.com/uniJlinu"!eatures/tools/
:
..//.)rite script to determine whether given file e7ist or not1 file name is supplied as command
line argument1 also chec for sufficient number of command line argument
:;/bin/bash
:
: <inu" 8hell 8cripting 5utorial 1.&=r, 8ummer-(&&(
:
: >ritten b, ?ivek @. @ite AvivekBni"cra!t.com$
:
: <atest version can be !ound at http+//www.ni"cra!t.com/
:
: C11
i! D $: -ne 1 E
then
echo FGsage - $& !ile-nameF
e"it 1
!i
i! D -! $1 E
then
echo F$1 !ile e"istF
else
echo F8orr,, $1 !ile does not e"istF
!i

:
: ./ch.sh+ vivek-tech.com to ni"cra!t.com re!erance converted using this tool
: 8ee the tool at http+//www.ni"cra!t.com/uniJlinu"!eatures/tools/
:

Anda mungkin juga menyukai