Your SlideShare is downloading. ×
UNIXTOOLBOX
4GHRCNBTLDMSHR@BNKKDBSHNMNE5MHW,HMTW3$BNLL@MCR@MCS@RJRVGHBG@QDTRDETKENQ)4VNQJ
NQENQ@CU@MBDCTRDQR4GHRHR@OQ@BSHB...
GNVDUDQSGDQD@CDQHR
RTOONRDCSNJMNVVG@SRGDHRCNHMF
3XRSDL
0QNBDRRDR
HKD3XRSDL
.DSVNQJ
33(3#0
60.VHSG33(
239.#
35$/
%MBQXOSHKD...
1SYSTEM
(@QCV@QDO	[3S@SHRSHBRO	[5RDQRO	[,HLHSRO	[2TMKDUDKRO	[QNNSO@RRVNQCO	[
#NLOHKDJDQMDKO	[2DO@HQFQTAO	[-HRBO	
2TMMHMFJD...
QDCG@S
FDMSNN
L@MCQ@JD
RTM3NK@QHR
@MCRN
NM3DD@KRN/etc/issue
#uptime#Showhowlongthesystemhasbeenrunning+load
#hostname#system'shostname
#hostname-i#Displayth...
3GNQS,HMTWQDEDQDMBDVVVOHWDKAD@SNQFBLCKHMDGSLK
,HSSKDBNLL@MCKHMDFNNCHDRVVVRGDKK
ETNQF
4G@SR@KKENKJR
4GHRCNBTLDMS5MHW4NNKANW...
QTM#pwd_mkdb
-pmaster.passwdSNQDATHKCSGDC@S@A@RD
4NSDLONQ@QHKXOQDUDMSKNFHMRRXRSDLVHCDENQ@KKTRDQRATSQNNS	TRDMNKNFHM4GDLDRR@...
C@S@A@RD	4GDCDE@TKSKHLHSR@QDTRT@KKXSNNKNV
Linux
Pershell/script
4GDRGDKKKHLHSR@QDFNUDQMDCAXulimit4GDRS@STRHRBGDBJDCVHSGuli...
FreeBSD
Pershell/script
5RDSGDBNLL@MClimitsHMBRGNQSBRGNQ@RHM,HMTW
TRDulimitHM@MRGNQA@RGRGDKK
Peruser/process
4GDCDE@TKSKHLHSRNMKNFHM@QDRDSHM/etc/login.conf!MTMKHLHSDCU@KTDHRRSHKKKHLHSDCAXS...
SGDJDQMDKRS@QSRinitVGHBGSGDMRS@QSRrcVGHBGRS@QSR@KKRBQHOSRADKNMFHMFSN@
QTMKDUDK4GDRBQHOSR@QDRSNQDCHMDSBHMHSC@MC@QDKHMJDCHMS...
@MC@MCRGTSCNVMHM
@MC
GSSOVVVEQDDARCNQFG@MCANNJBNMEHFSTMHMF
JDQMDK
KHLHSRGSLK
GSSORDQUDQE@TKSBNLPTDRSHNMREQDDARC
ODQENQL@MBD
STMHMF
RXRBSKR
...
#gccsimple.c-osimple
#./simple
Theansweris42
22.3C++basics
*pointer//Objectpointedtobypointer
obj//Addressofobjectobj
obj....
SGDQD@QDMNQTMKDUDKR4GDEHM@KANNSRS@SD
RHMFKDTRDQ
VHSGNQVHSGNTS8	HRBNMEHFTQDCHM/etc/ttys!KK/3RBQHOSR@QDKNB@SDCHM/etc/
rc.d/@MCHM/usr/local/etc/rc.d/ENQSGHQC
O@QSX@OOKHB@SHN...
DMSDQSGDENKKNVHMFANNSNOSHNM
init=/bin/sh
4GDJDQMDKVHKKLNTMSSGDQNNSO@QSHSHNM@MCinitVHKKRS@QSSGDANTQMDRGDKKHMRSD@CNErc@MCSGD...
@ESDQANNSHMF
SGDQNNSO@QSHSHNMHRLNTMSDCQD@CNMKX
QDLNTMSHSQV
#mount-oremount,rw/
#passwd#ordeletetherootpassword(/etc/shadow)
#sync;mount-oremount,ro/#syncbeforetoremountr...
ANNSHMRHMFKDTRDQLNCD
QDLNTMSQV@MCTRDO@RRVC9NTB@MRDKDBSSGDRHMFKD
TRDQLNCDNMSGDANNSLDMTNOSHNM	VGHBGHRCHROK@XDCENQRDBNMCR@SRS@QSTO4GDRHMFKD
TRDQLN...
UnixesandFreeBSDandLinuxmethod2
/SGDQ5MHWDRLHFGSMNSKDSXNTFN@V@XVHSGSGDRHLOKDHMHSSQHBJ4GDRNKTSHNMHRSNLNTMSSGDQNNS
O@QSHSHNM...
BNOXSGDFDMDQHBBNMEHFTQ@SHNMEHKDSN@MDVM@LD@MCDCHSHS@R
MDDCDCXNTB@M@KRNDCHSSGDEHKDGENERICCHQDBSKX	4NQDRS@QSSGDATHKC@ESDQ@MHM...
@CC
SGDNOSHNMNO_CLEAN=YESSNSGDL@JDBNLL@MCSN@UNHCBKD@MHMFSGDNAIDBSR@KQD@CXATHKC
#cd/usr/src/sys/i386/conf/
#cpGENERICMYKERN...
Generateafile
MYHOME=/home/colin
cattesthome.sh_EOF
#Allofthisgoesintothefiletesthome.sh
if[-d$MYHOME];then
echo$MYHOMEexi...
SGDRBQHOSTRDCSNBQD@SD@0$ANNJKDSEQNLSGHRWGSLKCNBTLDMS
#!/bin/sh
#Thisscriptcreatesabookinpdfformatreadytoprintonaduplexprin...
Upcoming SlideShare
Loading in...5
×

unixtoolbox.book

394

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
394
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "unixtoolbox.book"

  1. 1. UNIXTOOLBOX 4GHRCNBTLDMSHR@BNKKDBSHNMNE5MHW,HMTW3$BNLL@MCR@MCS@RJRVGHBG@QDTRDETKENQ)4VNQJ NQENQ@CU@MBDCTRDQR4GHRHR@OQ@BSHB@KFTHCDVHSGBNMBHRDDWOK@M@SHNMR
  2. 2. GNVDUDQSGDQD@CDQHR RTOONRDCSNJMNVVG@SRGDHRCNHMF 3XRSDL 0QNBDRRDR HKD3XRSDL .DSVNQJ 33(3#0 60.VHSG33( 239.# 35$/ %MBQXOSHKDR %MBQXOS0@QSHSHNMR 33,#DQSHEHB@SDR #63 36. 5RDETK#NLL@MCR )MRS@KK3NESV@QD #NMUDQS-DCH@ 0QHMSHMF $@S@A@RDR $HRJ1TNS@ 3GDKKR 3BQHOSHMF 0QNFQ@LLHMF /MKHMD(DKO 5MHW4NNKANWQDUHRHNM 4GDK@SDRSUDQRHNMNESGHRCNBTLDMSB@MADENTMC@SGSSOBAUTTMHWSNNKANWWGSLK2DOK@BDWGSLK NMSGDKHMJVHSGOCEENQSGD0$UDQRHNM@MCVHSGANNJOCEENQSGDANNJKDSUDQRHNM/M@CTOKDW OQHMSDQSGDANNJKDSVHKKBQD@SD@RL@KKANNJQD@CXSNAHMC3DD@KRNSGD@ANTSO@FD %QQNQQDONQSR@MCBNLLDMSR@QDLNRSVDKBNLD BBAUT#NKHM@QRBGDK
  3. 3. 1SYSTEM (@QCV@QDO [3S@SHRSHBRO [5RDQRO [,HLHSRO [2TMKDUDKRO [QNNSO@RRVNQCO [ #NLOHKDJDQMDKO [2DO@HQFQTAO [-HRBO 2TMMHMFJDQMDK@MCRXRSDLHMENQL@SHNM #uname-a#Getthekernelversion(andBSDversion) #lsb_release-a#FullreleaseinfoofanyLSBdistribution #cat/etc/SuSE-release#GetSuSEversion #cat/etc/debian_version#GetDebianversion 5RDDSBDISTR QDKD@RDVHSGDISTR=KRA5ATMST
  4. 4. QDCG@S
  5. 5. FDMSNN
  6. 6. L@MCQ@JD
  7. 7. RTM3NK@QHR
  8. 8. @MCRN NM3DD@KRN/etc/issue #uptime#Showhowlongthesystemhasbeenrunning+load #hostname#system'shostname #hostname-i#DisplaytheIPaddressofthehost.(Linuxonly) #manhier#Descriptionofthefilesystemhierarchy #lastreboot#Showsystemreboothistory 1.1HardwareInformations +DQMDKCDSDBSDCG@QCV@QD #dmesg#Detectedhardwareandbootmessages #lsdev#informationaboutinstalledhardware #ddif=/dev/membs=1kskip=768count=2562/dev/null|strings-n8#ReadBIOS Linux #cat/proc/cpuinfo#CPUmodel #cat/proc/meminfo#Hardwarememory #grepMemTotal/proc/meminfo#Displaythephysicalmemory #watch-n1'cat/proc/interrupts'#Watchchangeableinterruptscontinuously #free-m#Usedandfreememory(-mforMB) #cat/proc/devices#Configureddevices #lspci-tv#ShowPCIdevices #lsusb-tv#ShowUSBdevices #lshal#Showalistofalldeviceswiththeirproperties #dmidecode#ShowDMI/SMBIOS:hwinfofromtheBIOS FreeBSD #sysctlhw.model#CPUmodel #sysctlhw#Givesalotofhardwareinformation #sysctlhw.ncpu#numberofactiveCPUsinstalled #sysctlvm#Memoryusage #sysctlhw.realmem#Hardwarememory #sysctl-a|grepmem#Kernelmemorysettingsandinfo #sysctldev#Configureddevices #pciconf-l-cv#ShowPCIdevices #usbdevs-v#ShowUSBdevices #atacontrollist#ShowATAdevices #camcontroldevlist-v#ShowSCSIdevices 1.2Load,statisticsandmessages 4GDENKKNVHMFBNLL@MCR@QDTRDETKSNEHMCNTSVG@SHRFNHMFNMNMSGDRXRSDL #top#displayandupdatethetopcpuprocesses #mpstat1#displayprocessorsrelatedstatistics #vmstat2#displayvirtualmemorystatistics #iostat2#displayI/Ostatistics(2sintervals) #systat-vmstat1#BSDsummaryofsystemstatistics(1sintervals) #systat-tcp1#BSDtcpconnections(tryalso-ip) #systat-netstat1#BSDactivenetworkconnections #systat-ifstat1#BSDnetworktrafficthroughactiveinterfaces c3XRSDLc
  9. 9. 3GNQS,HMTWQDEDQDMBDVVVOHWDKAD@SNQFBLCKHMDGSLK ,HSSKDBNLL@MCKHMDFNNCHDRVVVRGDKK ETNQF 4G@SR@KKENKJR 4GHRCNBTLDMS5MHW4NNKANWQDUHRHNMHRKHBDMRDCTMCDQ@#QD@SHUD#NLLNMR,HBDMBD ;!SSQHATSHNM 3G@QD!KHJD=b#NKHM@QRBGDK 3NLDQHFGSRQDRDQUDC c/MKHMD(DKOc #systat-iostat1#BSDCPUandanddiskthroughput #ipcs-a#informationonSystemVinterprocess #tail-n500/var/log/messages#Last500kernel/syslogmessages #tail/var/log/warn#Systemwarningsmessagesseesyslog.conf 1.3Users #id#Showtheactiveuseridwithloginandgroup #last#Showlastloginsonthesystem #who#Showwhoisloggedonthesystem #groupaddadmin#Addgroupadminandusercolin(Linux/Solaris) #useradd-cColinBarschel-gadmin-mcolin #usermod-a-Ggroupuser#Addexistingusertogroup(Debian) #groupmod-Ausergroup#Addexistingusertogroup(SuSE) #userdelcolin#Deleteusercolin(Linux/Solaris) #adduserjoe#FreeBSDadduserjoe(interactive) #rmuserjoe#FreeBSDdeleteuserjoe(interactive) #pwgroupaddadmin#UsepwonFreeBSD #pwgroupmodadmin-mnewmember#Addanewmembertoagroup #pwuseraddcolin-cColinBarschel-gadmin-m-s/bin/tcsh #pwuserdelcolin;pwgroupdeladmin %MBQXOSDCO@RRVNQCR@QDRSNQDCHMDSBRG@CNVENQ,HMTW@MC3NK@QHR@MCDSBL@RSDQO@RRVCNM QDD3$)ESGDL@RSDQO@RRVCHRLNCHEHDCL@MT@KKXR@XSNCDKDSD@O@RRVNQC
  10. 10. QTM#pwd_mkdb -pmaster.passwdSNQDATHKCSGDC@S@A@RD 4NSDLONQ@QHKXOQDUDMSKNFHMRRXRSDLVHCDENQ@KKTRDQRATSQNNS TRDMNKNFHM4GDLDRR@FDHM MNKNFHMVHKKADCHROK@XDCLHFGSMNSVNQJVHSGRRGOQD RG@QDCJDXR #echoSorrynologinnow/etc/nologin#(Linux) #echoSorrynologinnow/var/run/nologin#(FreeBSD) 1.4Limits 3NLD@OOKHB@SHNMQDPTHQDGHFGDQKHLHSRNMNODMEHKDR@MCRNBJDSRKHJD@OQNWXVDARDQUDQ
  11. 11. C@S@A@RD 4GDCDE@TKSKHLHSR@QDTRT@KKXSNNKNV Linux Pershell/script 4GDRGDKKKHLHSR@QDFNUDQMDCAXulimit4GDRS@STRHRBGDBJDCVHSGulimit-aNQDW@LOKDSN BG@MFDSGDNODMEHKDRKHLHSEQNLSNCN #ulimit-n10240#Thisisonlyvalidwithintheshell 4GDulimitBNLL@MCB@MADTRDCHM@RBQHOSSNBG@MFDSGDKHLHSRENQSGDRBQHOSNMKX Peruser/process ,NFHMTRDQR@MC@OOKHB@SHNMRB@MADBNMEHFTQDCHM/etc/security/limits.confNQDW@LOKD #cat/etc/security/limits.conf *hardnproc250#Limituserprocesses asteriskhardnofile409600#Limitapplicationopenfiles Systemwide +DQMDKKHLHSR@QDRDSVHSGRXRBSK0DQL@MDMSKHLHSR@QDRDSHM/etc/sysctl.conf #sysctl-a#Viewallsystemlimits #sysctlfs.file-max#Viewmaxopenfileslimit #sysctlfs.file-max=102400#Changemaxopenfileslimit #echo102450000/proc/sys/net/ipv4/ip_local_port_range#portrange #cat/etc/sysctl.conf fs.file-max=102400#Permanententryinsysctl.conf #cat/proc/sys/fs/file-nr#Howmanyfiledescriptorsareinuse c3XRSDLc
  12. 12. FreeBSD Pershell/script 5RDSGDBNLL@MClimitsHMBRGNQSBRGNQ@RHM,HMTW
  13. 13. TRDulimitHM@MRGNQA@RGRGDKK Peruser/process 4GDCDE@TKSKHLHSRNMKNFHM@QDRDSHM/etc/login.conf!MTMKHLHSDCU@KTDHRRSHKKKHLHSDCAXSGD RXRSDLL@WHL@KU@KTD Systemwide +DQMDKKHLHSR@QD@KRNRDSVHSGRXRBSK0DQL@MDMSKHLHSR@QDRDSHM/etc/sysctl.confNQ/boot/ loader.conf4GDRXMS@WHRSGDR@LD@R,HMTWATSSGDJDXR@QDCHEEDQDMS #sysctl-a#Viewallsystemlimits #sysctlkern.maxfiles=XXXX#maximumnumberoffiledescriptors kern.ipc.nmbclusters=32768#Permanententryin/etc/sysctl.conf kern.maxfiles=65536#TypicalvaluesforSquid kern.maxfilesperproc=32768 kern.ipc.somaxconn=8192#TCPqueue.Betterforapache/sendmail #sysctlkern.openfiles#Howmanyfiledescriptorsareinuse #sysctlkern.ipc.numopensockets#Howmanyopensocketsareinuse #sysctlnet.inet.ip.portrange.last=50000#Defaultis1024-5000 #netstat-m#networkmemorybuffersstatistics 3DD4GDQDD3$G@MCANNJ#G@OSDQ ENQCDS@HKR!MC@KRNQDD3$ODQENQL@MBDSTMHMF Solaris 4GDENKKNVHMFU@KTDRHM/etc/systemVHKKHMBQD@RDSGDL@WHLTLEHKDCDRBQHOSNQRODQOQNB setrlim_fd_max=4096#Hardlimitonfiledescriptorsforasingleproc setrlim_fd_cur=1024#Softlimitonfiledescriptorsforasingleproc 1.5Runlevels Linux /MBDANNSDC
  14. 14. SGDJDQMDKRS@QSRinitVGHBGSGDMRS@QSRrcVGHBGRS@QSR@KKRBQHOSRADKNMFHMFSN@ QTMKDUDK4GDRBQHOSR@QDRSNQDCHMDSBHMHSC@MC@QDKHMJDCHMSNDSBQBCQB.CVHSG.SGDQTMKDUDK MTLADQ 4GDCDE@TKSQTMKDUDKHRBNMEHFTQDCHMDSBHMHSS@A)SHRTRT@KKXNQ #grepdefault:/etc/inittab id:3:initdefault: 4GD@BST@KQTMKDUDKB@MADBG@MFDCVHSGinitNQDW@LOKDSNFNEQNLSN #init5#Entersrunlevel5 3GTSCNVM@MCG@KS 3HMFKD 5RDQLNCD@KRN3 -TKSH TRDQVHSGNTSMDSVNQJ -TKSH TRDQVHSGMDSVNQJ -TKSH TRDQVHSG8 2DANNS 5RDchkconfigSNBNMEHFTQDSGDOQNFQ@LRSG@SVHKKADRS@QSDC@SANNSHM@QTMKDUDK #chkconfig--list#Listallinitscripts #chkconfig--listsshd#Reportthestatusofsshd #chkconfigsshd--level35on#Configuresshdforlevels3and5 #chkconfigsshdoff#Disablesshdforallrunlevels $DAH@M@MC$DAH@MA@RDCCHRSQHATSHNMRKHJD5ATMSTNQ+MNOOHWTRDSGDBNLL@MCupdate-rc.dSN L@M@FDSGDQTMKDUDKRRBQHOSR$DE@TKSHRSNRS@QSHM
  15. 15. @MC@MCRGTSCNVMHM
  16. 16. @MC GSSOVVVEQDDARCNQFG@MCANNJBNMEHFSTMHMF JDQMDK KHLHSRGSLK GSSORDQUDQE@TKSBNLPTDRSHNMREQDDARC ODQENQL@MBD STMHMF RXRBSKR KN@CDQ BNME JDQMDK c3XRSDLc Theprogramsimplecpp.cpp #includeIPv4.h #includeiostream #includestring usingnamespacestd; intmain(intargc,char*argv[]){ stringipstr;//definevariables unsignedlongipint=1347861486;//TheIPinintegerform GenericUtils::IPv4iputils;//createanobjectoftheclass ipstr=iputils.IPint_to_IPquad(ipint);//calltheclassmember coutipint=ipstrendl;//printtheresult return0; } #NLOHKD@MCDWDBTSDVHSG #g++-cIPv4.cppsimplecpp.cpp#Compileinobjects #g++IPv4.osimplecpp.o-osimplecpp.exe#Linktheobjectstofinalexecutable #./simplecpp.exe 1347861486=80.86.187.238 5RDlddSNBGDBJVGHBGKHAQ@QHDR@QDTRDCAXSGDDWDBTS@AKD@MCVGDQDSGDX@QDKNB@SDC!KRNTRDC SNBGDBJHE@RG@QDCKHAQ@QXHRLHRRHMFNQHESGDDWDBTS@AKDHRRS@SHB #ldd/sbin/ifconfig#listdynamicobjectdependencies #arrcsstaticlib.a*.o#createstaticarchive #artstaticlib.a#printtheobjectslistfromthearchive #arx/usr/lib/libc.aversion.o#extractanobjectfilefromthearchive #nmversion.o#showfunctionmembersprovidedbyobject 22.5SimpleMakefile 4GDLHMHL@K-@JDEHKDENQSGDLTKSH RNTQBDOQNFQ@LHRRGNVMADKNV4GDKHMDRVHSGHMRSQTBSHNMRmust beginwithatab4GDA@BJRK@RGB@MADTRDCSNBTSKNMFKHMDR CC=g++ CFLAGS=-O OBJS=IPv4.osimplecpp.o simplecpp:${OBJS} ${CC}-osimplecpp${CFLAGS}${OBJS} clean: rm-f${TARGET}${OBJS} 23ONLINEHELP 23.1Documentation ,HMTW$NBTLDMS@SHNMDMSKCONQF ,HMTW-@M0@FDRVVVKHMTWL@MO@FDRBNL ,HMTWBNLL@MCRCHQDBSNQXVVVNQDHKKXMDSBNLKHMTWBLC ,HMTWCNBL@MGNVSNRKHMTWCHDMDS QDD3$(@MCANNJVVVEQDDARCNQFG@MCANNJ QDD3$-@M0@FDRVVVEQDDARCNQFBFHL@MBFH QDD3$TRDQVHJHVVVEQDDARCVHJHMDS 3NK@QHR-@M0@FDRCNBRRTMBNL@OOCNBRBNKK 23.2OtherUnix/Linuxreferences 2NRDSS@3SNMDENQ5MHWAG@LHBNLQNRDSS@GSLK@5MHWBNLL@MCSQ@MRK@SNQ 5MHWFTHCDBQNRRQDEDQDMBDTMHWFTHCDMDSTMHWFTHCDRGSLK ,HMTWBNLL@MCRKHMDKHRSVVVKHMTWBLCNQF c/MKHMD(DKOc
  17. 17. #gccsimple.c-osimple #./simple Theansweris42 22.3C++basics *pointer//Objectpointedtobypointer obj//Addressofobjectobj obj.x//Memberxofclassobj(objectobj) pobj-x//Memberxofclasspointedtobypobj //(*pobj).xandpobj-xarethesame 22.4C++example !R@RKHFGSKXLNQDQD@KHRSHBOQNFQ@LHM#@BK@RRHMHSRNVMGD@CDQ)0UG @MCHLOKDLDMS@SHNM )0UBOO @MC@OQNFQ@LVGHBGTRDRSGDBK@RRETMBSHNM@KHSX4GDBK@RRBNMUDQSR@M)0@CCQDRRHM HMSDFDQENQL@SSNSGDJMNVMPT@CENQL@S IPv4class IPv4.h: #ifndefIPV4_H #defineIPV4_H #includestring namespaceGenericUtils{//createanamespace classIPv4{//classdefinition public: IPv4();~IPv4(); std::stringIPint_to_IPquad(unsignedlongip);//memberinterface }; }//namespaceGenericUtils #endif//IPV4_H IPv4.cpp: #includeIPv4.h #includestring #includesstream usingnamespacestd;//usethenamespaces usingnamespaceGenericUtils; IPv4::IPv4(){}//defaultconstructor/destructor IPv4::~IPv4(){} stringIPv4::IPint_to_IPquad(unsignedlongip){//memberimplementation ostringstreamipstr;//useastringstream ipstr((ip0xff000000)24)//Bitwiserightshift .((ip0x00ff0000)16) .((ip0x0000ff00)8) .((ip0x000000ff)); returnipstr.str(); } c0QNFQ@LLHMFc #update-rc.dsshddefaults#Activatesshdwiththedefaultrunlevels #update-rc.dsshdstart202345.stop20016.#Withexplicitarguments #update-rc.d-fsshdremove#Disablesshdforallrunlevels #shutdown-hnow(or#poweroff)#Shutdownandhaltthesystem FreeBSD 4GD3$ANNS@OOQN@BGHRCHEEDQDMSEQNLSGD3XR6
  18. 18. SGDQD@QDMNQTMKDUDKR4GDEHM@KANNSRS@SD RHMFKDTRDQ
  19. 19. VHSGNQVHSGNTS8 HRBNMEHFTQDCHM/etc/ttys!KK/3RBQHOSR@QDKNB@SDCHM/etc/ rc.d/@MCHM/usr/local/etc/rc.d/ENQSGHQC O@QSX@OOKHB@SHNMR4GD@BSHU@SHNMNESGDRDQUHBDHR BNMEHFTQDCHM/etc/rc.conf@MC/etc/rc.conf.local4GDCDE@TKSADG@UHNQHRBNMEHFTQDCHM/etc/ defaults/rc.conf4GDRBQHOSRQDRONMCR@SKD@RSSNRS@QS[RSNO[RS@STR #/etc/rc.d/sshdstatus sshdisrunningaspid552. #shutdownnow#Gointosingle-usermode #exit#Gobacktomulti-usermode #shutdown-pnow#Shutdownandhaltthesystem #shutdown-rnow#Reboot 4GDOQNBDRRinitB@M@KRNADTRDCSNQD@BGNMDNESGDENKKNVHMFRS@SDRKDUDKNQDW@LOKD#init 6ENQQDANNS (@KS@MCSTQMSGDONVDQNEERHFM@KUSR2 'NSNRHMFKD TRDQLNCDRHFM@KTERM 2DANNSSGDL@BGHMDRHFM@KINT BKNBJETQSGDQKNFHMRRHFM@KTSTP P2DRB@MSGDSSXR EHKDRHFM@KHUP Windows 3S@QS@MCRSNO@RDQUHBDVHSGDHSGDQSGDservicenameNQservicedescriptionRGNVMHMSGD 3DQUHBDR#NMSQNK0@MDK @RENKKNVR netstopWSearch netstartWSearch#startsearchservice netstopWindowsSearch netstartWindowsSearch#sameasaboveusingdescr. 1.6Resetrootpassword Linuxmethod1 !SSGDANNSKN@CDQKHKNNQFQTA
  20. 20. DMSDQSGDENKKNVHMFANNSNOSHNM init=/bin/sh 4GDJDQMDKVHKKLNTMSSGDQNNSO@QSHSHNM@MCinitVHKKRS@QSSGDANTQMDRGDKKHMRSD@CNErc@MCSGDM@ QTMKDUDK5RDSGDBNLL@MCpasswd@SSGDOQNLOSSNBG@MFDSGDO@RRVNQC@MCSGDMQDANNSNQFDS SGDRHMFKDTRDQLNCD@RXNTMDDCSGDO@RRVNQCENQSG@S )E
  21. 21. @ESDQANNSHMF
  22. 22. SGDQNNSO@QSHSHNMHRLNTMSDCQD@CNMKX
  23. 23. QDLNTMSHSQV #mount-oremount,rw/ #passwd#ordeletetherootpassword(/etc/shadow) #sync;mount-oremount,ro/#syncbeforetoremountreadonly #reboot FreeBSDmethod1 /MQDD3$
  24. 24. ANNSHMRHMFKDTRDQLNCD
  25. 25. QDLNTMSQV@MCTRDO@RRVC9NTB@MRDKDBSSGDRHMFKD TRDQLNCDNMSGDANNSLDMTNOSHNM VGHBGHRCHROK@XDCENQRDBNMCR@SRS@QSTO4GDRHMFKD TRDQLNCDVHKKFHUDXNT@QNNSRGDKKNMSGDO@QSHSHNM #mount-u/;mount-a#willmount/rw #passwd #reboot c3XRSDLc
  26. 26. UnixesandFreeBSDandLinuxmethod2 /SGDQ5MHWDRLHFGSMNSKDSXNTFN@V@XVHSGSGDRHLOKDHMHSSQHBJ4GDRNKTSHNMHRSNLNTMSSGDQNNS O@QSHSHNMEQNL@MNSGDQ/3KHJD@QDRBTD#$ @MCBG@MFDSGDO@RRVNQCNMSGDCHRJ aNNS@KHUD#$NQHMRS@KK@SHNM#$HMSN@QDRBTDLNCDVGHBGVHKKFHUDXNT@RGDKK aHMCSGDQNNSO@QSHSHNMVHSGECHRJDFECHRJCDURC@ a-NTMSHS@MCTRDBGQNNS #mount-orw/dev/ad4s3a/mnt #chroot/mnt#chrootinto/mnt #passwd #reboot 1.7Kernelmodules Linux #lsmod#Listallmodulesloadedinthekernel #modprobeisdn#Toloadamodule(hereisdn) FreeBSD #kldstat#Listallmodulesloadedinthekernel #kldloadcrypto#Toloadamodule(herecrypto) 1.8CompileKernel Linux #cd/usr/src/linux #makemrproper#Cleaneverything,includingconfigfiles #makeoldconfig#Reusetheold.configifexistent #makemenuconfig#orxconfig(Qt)orgconfig(GTK) #make#Createacompressedkernelimage #makemodules#Compilethemodules #makemodules_install#Installthemodules #makeinstall#Installthekernel #reboot FreeBSD /OSHNM@KKXTOC@SDSGDRNTQBDSQDDHM/usr/src VHSGBRTO@RNEQDD3$NQK@SDQ #csupsupfile )TRDSGDENKKNVHMFRTOEHKD *defaulthost=cvsup5.FreeBSD.org#www.freebsd.org/handbook/cvsup.html#CVSUP-MIRRORS *defaultprefix=/usr *defaultbase=/var/db *defaultrelease=cvsdeletetag=RELENG_7 src-all 4NLNCHEX@MCQDATHKCSGDJDQMDK
  27. 27. BNOXSGDFDMDQHBBNMEHFTQ@SHNMEHKDSN@MDVM@LD@MCDCHSHS@R MDDCDCXNTB@M@KRNDCHSSGDEHKDGENERICCHQDBSKX 4NQDRS@QSSGDATHKC@ESDQ@MHMSDQQTOSHNM
  28. 28. @CC SGDNOSHNMNO_CLEAN=YESSNSGDL@JDBNLL@MCSN@UNHCBKD@MHMFSGDNAIDBSR@KQD@CXATHKC #cd/usr/src/sys/i386/conf/ #cpGENERICMYKERNEL #cd/usr/src #makebuildkernelKERNCONF=MYKERNEL #makeinstallkernelKERNCONF=MYKERNEL 4NQDATHKCSGDETKK/3 #makebuildworld#BuildthefullOSbutnotthekernel #makebuildkernel#UseKERNCONFasaboveifappropriate #makeinstallkernel #reboot #mergemaster-p#Comparesonlyfilesknowntobeessential c3XRSDLc [^$.|?*+()#specialcharactersanyotherwillmatchthemselves #escapesspecialcharactersandtreatasliteral *#repeatthepreviousitemzeroormoretimes .#singlecharacterexceptlinebreakcharacters .*#matchzeroormorecharacters ^#matchatthestartofaline/string $#matchattheendofaline/string .$#matchasinglecharacterattheendofline/string ^$#matchlinewithasinglespace [^A-Z]#matchanylinebeginningwithanycharfromAtoZ 21.6Someusefulcommands 4GDENKKNVHMFBNLL@MCR@QDTRDETKSNHMBKTCDHM@RBQHOSNQ@RNMDKHMDQR sort-t.-k1,1n-k2,2n-k3,3n-k4,4n#SortIPv4ipaddresses echo'Test'|tr'[:lower:]''[:upper:]'#Caseconversion echofoo.bar|cut-d.-f1#Returnsfoo PID=$(ps|grepscript.sh|grepbin|awk'{print$1}')#PIDofarunningscript PID=$(psaxww|grep[p]ing|awk'{print$1}')#PIDofping(w/ogreppid) IP=$(ifconfig$INTERFACE|sed'/.*inetaddr:/!d;s///;s/.*//')#Linux IP=$(ifconfig$INTERFACE|sed'/.*inet/!d;s///;s/.*//')#FreeBSD if[`difffile1file2|wc-l`!=0];then[...]fi#Filechanged? cat/etc/master.passwd|grep-vroot|grep-v*:|awk-F:#Createhttppasswd '{printf(%s:%sn,$1,$2)}'/usr/local/etc/apache2/passwd testuser=$(cat/usr/local/etc/apache2/passwd|grep-v#Checkuserinpasswd root|grep-v*:|awk-F:'{printf(%sn,$1)}'|grep^user$) :(){:|:};:#bashforkbomb.Willkillyourmachine tail+2filefile2#removethefirstlinefromfile )TRDSGHRKHSSKDSQHBJSNBG@MFDSGDEHKDDWSDMRHNMENQL@MXEHKDR@SNMBDNQDW@LOKDEQNLBWWSN BOO4DRSHSEHQRSVHSGNTSSGD|sh@SSGDDMC9NTB@M@KRNCNSGHRVHSGSGDBNLL@MCrenameHE HMRS@KKDC/QVHSGA@RGATHKSHMR #ls*.cxx|awk-F.'{printmv$0$1.cpp}'|sh #ls*.c|seds/.*/cp.$(date+%Y%m%d)/|sh#e.g.copy*.cto*.c.20080401 #rename.cxx.cpp*.cxx#Renameall.cxxtocpp #foriin*.cxx;domv$i${i%%.cxx}.cpp;done#withbashbuiltins 22PROGRAMMING 22.1Cbasics strcpy(newstr,str)/*copystrtonewstr*/ expr1?expr2:expr3/*if(expr1)expr2elseexpr3*/ x=(yz)?y:z;/*if(yz)x=y;elsex=z;*/ inta[]={0,1,2};/*Initializedarray(ora[3]={0,1,2};*/ inta[2][3]={{1,2,3},{4,5,6}};/*Arrayofarrayofints*/ inti=12345;/*Convertinitocharstr*/ charstr[10]; sprintf(str,%d,i); 22.2Cexample !LHMHL@KBOQNFQ@LRHLOKDB #includestdio.h main(){ intnumber=42; printf(Theansweris%in,number); } #NLOHKDVHSG c0QNFQ@LLHMFc
  29. 29. Generateafile MYHOME=/home/colin cattesthome.sh_EOF #Allofthisgoesintothefiletesthome.sh if[-d$MYHOME];then echo$MYHOMEexists else echo$MYHOMEdoesnotexist fi _EOF shtesthome.sh 21.2Bournescriptexample !R@RL@KKDW@LOKD
  30. 30. SGDRBQHOSTRDCSNBQD@SD@0$ANNJKDSEQNLSGHRWGSLKCNBTLDMS #!/bin/sh #Thisscriptcreatesabookinpdfformatreadytoprintonaduplexprinter if[$#-ne1];then#Checktheargument echo12Usage:$0HtmlFile exit1#nonzeroexitiferror fi file=$1#Assignthefilename fname=${file%.*}#Getthenameofthefileonly fext=${file#*.}#Gettheextensionofthefile prince$file-o$fname.pdf#fromwww.princexml.com pdftops-paperA4-noshrink$fname.pdf$fname.ps#createpostscriptbooklet cat$fname.ps|psbook|psnup-Pa4-2|pstops-b2:0,1U(21cm,29.7cm)$fname.book.ps ps2pdf13-sPAPERSIZE=a4-sAutoRotatePages=None$fname.book.ps$fname.book.pdf #use#a4and#NoneonWindows! exit0#exit0meanssuccessful 21.3Someawkcommands !VJHRTRDETKENQEHDKCRSQHOOHMF
  31. 31. KHJDBTSHM@LNQDONVDQETKV@X3D@QBGSGHRCNBTLDMSENQNSGDQ DW@LOKDR3DDENQDW@LOKDFMTK@LOBNL@MCNMD KHMDQRENQ@VJENQRNLDMHBDDW@LOKDR awk'{print$2,$1}'file#Printandinversefirsttwocolumns awk'{printf(%5d:%sn,NR,$0)}'file#Addlinenumberleftaligned awk'{printFNRt$0}'files#Addlinenumberrightaligned awkNFtest.txt#removeblanklines(sameasgrep'.') awk'length80'#printlinelongerthan80char) 21.4Somesedcommands (DQDHRSGDNMDKHMDQFNKCLHMD !MC@FNNCHMSQNCTBSHNM@MCSTSNQH@KSNRDC sed's/string1/string2/g'#Replacestring1withstring2 sed-i's/wroong/wrong/g'*.txt#Replacearecurringwordwithg sed's/(.*)1/12/g'#Modifyanystring1toanystring2 sed'/p/,//p/d't.xhtml#Deletelinesthatstartwithp #andendwith/p sed'/*#/d;/^*$/d'#Removecommentsandblanklines sed's/[t]*$//'#Removetrailingspaces(usetabast) sed's/^[t]*//;s/[t]*$//'#Removeleadingandtrailingspaces sed's/[^*]/[]/'#Enclosefirstcharwith[]top-[t]op sed=file|sed'N;s/n/t/'file.num#Numberlinesonafile 21.5RegularExpressions 3NLDA@RHBQDFTK@QDWOQDRRHNMTRDETKENQRDCSNN3DD@RHB2DFDW3XMS@W ENQ@FNNCOQHLDQ GSSORSTCDMSMNQSGO@QJDCTODLDMSDRDCRDCKHMDSWS GSSOVVVFQXLNHQDBNL5MHW3DCGSLK GSSOVVVQDFTK@Q DWOQDRRHNMRHMENQDEDQDMBDGSLK c3BQHOSHMFc #makeinstallworld #mergemaster-i-U#Updateallconfigurationsandotherfiles #reboot NQRL@KKBG@MFDRHMSGDRNTQBDXNTB@MTRD./?#,%!.XDRSN@UNHCQDATHKCHMFSGDVGNKDSQDD #makebuildworldNO_CLEAN=yes#Don'tdeletetheoldobjects #makebuildkernelKERNCONF=MYKERNELNO_CLEAN=yes 1.9Repairgrub 3NXNTAQNJDFQTANNSEQNL@KHUDBC
  32. 32. ;EHMCXNTQKHMTWO@QSHSHNMTMCDQ/dev@MCTRDfdiskSNEHMC SGDKHMTWO@QSHNM=LNTMSSGDKHMTWO@QSHSHNM
  33. 33. @CCOQNB@MCCDU@MCTRDgrub-install/dev/xyz 3TOONRDKHMTWKHDRNM/dev/sda6 #mount/dev/sda6/mnt#mountthelinuxpartitionon/mnt #mount--bind/proc/mnt/proc#mounttheprocsubsysteminto/mnt #mount--bind/dev/mnt/dev#mountthedevicesinto/mnt #chroot/mnt#changeroottothelinuxpartition #grub-install/dev/sda#reinstallgrubwithyouroldsettings 1.10Misc $HR@AKD/38UHQST@KLDLNQXQDOD@SVHSGloadSNQD DM@AKD @RSDQRXRSDL
  34. 34. ATS@KHSSKDQHRJX #sudolaunchctlunload-w/System/Library/LaunchDaemons/com.apple.dynamic_pager.plist #sleep3600;pmsetsleepnow#gotostandbyinonehour(OSX) #defaultswrite-gcom.apple.mouse.scaling-float8 #OSXmouseacceleration(use-1toreverse) 2PROCESSES ,HRSHMFO [0QHNQHSXO [@BJFQNTMCNQDFQNTMCO [4NOO [+HKKO 2.1ListingandPIDs %@BGOQNBDRRG@R@TMHPTDMTLADQ
  35. 35. SGD0)$!KHRSNE@KKQTMMHMFOQNBDRRHRQDSQHDUDCVHSGps #ps-auxefw#Extensivelistofallrunningprocess (NVDUDQLNQDSXOHB@KTR@FDHRVHSG@OHODNQVHSGpgrepENQ/38HMRS@KKproctoolsEQNL-@B0NQSR O@FD #psaxww|grepcron 586??Is0:01.48/usr/sbin/cron-s #psaxjf#Allprocessesinatreeformat(Linux) #psaux|grep'ss[h]'#Findallsshpidswithoutthegreppid #pgrep-lsshd#FindthePIDsofprocessesby(partof)name #echo$$#ThePIDofyourshell #fuser-va22/tcp#Listprocessesusingport22(Linux) #pmapPID#Memorymapofprocess(huntmemoryleaks)(Linux) #fuser-va/home#Listprocessesaccessingthe/homepartition #stracedf#Tracesystemcallsandsignals #trussdf#sameasaboveonFreeBSD/Solaris/Unixware 2.2Priority #G@MFDSGDOQHNQHSXNE@QTMMHMFOQNBDRRVHSGreniceNegativenumbershaveahigherpriority
  36. 36. SGDKNVDRSHR @MCMHBDG@UD@ONRHSHUDU@KTD #renice-5586#Strongerpriority 586:oldpriority0,newpriority-5 3S@QSSGDOQNBDRRVHSG@CDEHMDCOQHNQHSXVHSGnice0NRHSHUDHRMHBDNQVD@J
  37. 37. MDF@SHUDHRRSQNMF RBGDCTKHMFOQHNQHSX-@JDRTQDXNTJMNVHE/usr/bin/niceNQSGDRGDKKATHKS HMHRTRDCBGDBJVHSG #whichnice c0QNBDRRDRc
  38. 38. #nice-n-5top#Strongerpriority(/usr/bin/nice) #nice-n5top#Weakerpriority(/usr/bin/nice) #nice+5top#tcshbuiltinnice(sameasabove!) 7GHKDMHBDBG@MFDRSGD#05RBGDCTKDQ
  39. 39. @MNSGDQTRDETKBNLL@MCioniceVHKKRBGDCTKDSGDCHRJ)/ 4GHRHRUDQXTRDETKENQHMSDMRHUD)/@OOKHB@SHNMDFBNLOHKHMF 9NTB@MRDKDBS@BK@RRHCKD ADRS DEENQS QD@KSHLD
  40. 40. SGDL@MO@FDHRRGNQS@MCVDKKDWOK@HMDC #ionicec3-p123#setidleclassforpid123(Linuxonly) #ionice-c2-n0firefox#Runfirefoxwithbesteffortandhighpriority #ionice-c3-p$$#Settheactualshelltoidlepriority 4GDK@RSBNLL@MCHRUDQXTRDETKSNBNLOHKDNQCDATF @K@QFDOQNIDBS%UDQXBNLL@MCK@TMBGDC EQNLSGHRRGDKKVHKKG@UD@KNUDQOQHNQHSX$$HRXNTQRGDKKOHCSQXDBGN QDD3$TRDRidprio/rtprioL@WOQHNQHSX
  41. 41. LNRSHCKD #idprio31make#compileinthelowestpriority #idprio31-1234#setPID1234withlowestpriority #idprio-t-1234#-tremovesanyrealtime/idlepriority 2.3Background/Foreground 7GDMRS@QSDCEQNL@RGDKK
  42. 42. OQNBDRRDRB@MADAQNTFGSHMSGDA@BJFQNTMC@MCA@BJSNSGDENQDFQNTMC VHSG;#SQK= ;:=:
  43. 43. bg@MCfg,HRSSGDOQNBDRRDRVHSGjobs7GDMMDDCDCCDS@BGEQNLSGD SDQLHM@KVHSGdisown #pingcb.vuping.log ^Z#pingissuspended(stopped)with[Ctrl]-[Z] #bg#putinbackgroundandcontinuesrunning #jobs-l#Listprocessesinbackground [1]-36232Runningpingcb.vuping.log [2]+36233Suspended(ttyoutput)top #fg%2#Bringprocess2backinforeground #make#startalongcompilejobbutneedtoleavetheterminal ^Z#suspended(stopped)with[Ctrl]-[Z] #bg#putinbackgroundandcontinuesrunning #disown-h%1#detatchprocessfromterminal,won'tbekilledatlogout .NRSQ@HFGSENQV@QCV@XSNQD @SS@BGSGDOQNBDRRSN@MDVSDQLHM@K
  44. 44. SQXQDOSXQ,HMTW 5RDnohupSNRS@QS@OQNBDRRVGHBGG@RSNJDDOQTMMHMFVGDMSGDRGDKKHRBKNRDCHLLTMDSN G@MFTOR #nohupping-i60ping.log 2.4Top 4GDOQNFQ@LtopCHROK@XRQTMMHMFHMENQL@SHNMNEOQNBDRRDR3DD@KRNSGDOQNFQ@LhtopEQNL GSNORNTQBDENQFDMDS@LNQDONVDQETKUDQRHNMNESNO VGHBGQTMRNM,HMTW@MCQDD3$ports/ sysutils/htop/ 7GHKDSNOHRQTMMHMFOQDRRSGDJDXGENQ@GDKONUDQUHDV5RDETKJDXR@QD au[username]4NCHROK@XNMKXSGDOQNBDRRDRADKNMFHMFSNSGDTRDQ5RDNQAK@MJSNRDD @KKTRDQR ak[pid]+HKKSGDOQNBDRRVHSGOHC a14NCHROK@X@KKOQNBDRRNQRRS@SHRSHBR,HMTWNMKX aR4NFFKDMNQL@KQDUDQRDRNQS 2.5Signals/Kill 4DQLHM@SDNQRDMC@RHFM@KVHSGkillNQkillall #ping-i60cb.vuping.log [1]4712 #kill-sTERM4712#sameaskill-154712 #killall-1httpd#KillHUPprocessesbyexactname #pkill-9http#KillTERMprocessesby(partof)name c0QNBDRRDRc 21SCRIPTING @RHBRO [3BQHOSDW@LOKDO [@VJO [RDCO [2DFTK@Q%WOQDRRHNMRO [TRDETK BNLL@MCRO 4GDNTQMDRGDKKAHMRG HROQDRDMSNM@KK5MHWHMRS@KK@SHNMR@MCRBQHOSRVQHSSDMHMSGHRK@MFT@FD @QDPTHSD ONQS@AKDman1shHR@FNNCQDEDQDMBD 21.1Basics Variablesandarguments !RRHFMVHSGU@QH@AKDU@KTD@MCFDSBNMSDMSVHSGU@QH@AKD MESSAGE=HelloWorld#Assignastring PI=3.1415#Assignadecimalnumber N=8 TWON=`expr$N*2`#Arithmeticexpression(onlyintegers) TWON=$(($N*2))#Othersyntax TWOPI=`echo$PI*2|bc-l`#Usebcforfloatingpointoperations ZERO=`echoc($PI/4)-sqrt(2)/2|bc-l` 4GDBNLL@MCKHMD@QFTLDMSR@QD $0,$1,$2,...#$0isthecommanditself $##Thenumberofarguments $*#Allarguments(also$@) SpecialVariables $$#ThecurrentprocessID $?#exitstatusoflastcommand command if[$?!=0];then echocommandfailed fi mypath=`pwd` mypath=${mypath}/file.txt echo${mypath##*/}#Displaythefilenameonly echo${mypath%%.*}#Fullpathwithoutextention foo=/tmp/my.dir/filename.tar.gz path=${foo%/*}#Fullpathwithoutextention var2=${var:=string}#Usevarifset,otherwiseusestring #assignstringtovarandthentovar2. size=$(stat-c%s$file)#getfilesizeinbournescript filesize=${size:=-1} Constructs forfilein`ls` do echo$file done count=0 while[$count-lt5];do echo$count sleep1 count=$(($count+1)) done myfunction(){ find.-typef-name*.$1-print#$1isfirstargumentofthefunction } myfunctiontxt c3BQHOSHMFc
  45. 45. #in.bashrc bind'e[A':history-search-backward#Useupanddownarrowtosearch bind'e[B':history-search-forward#thehistory.Invaluable! set-oemacs#Setemacsmodeinbash(seebelow) setbell-stylevisible#Donotbeep,inversecolors #Setanicepromptlike[user@host]/path/todir PS1=[033[1;30m][[033[1;34m]u[033[1;30m] PS1=$PS1@[033[0;33m]h[033[1;30m]][033[0;37m] PS1=$PS1w[033[1;30m][033[0m] #Tocheckthecurrentlyactivealiases,simplytypealias aliasls='ls-aF'#Appendindicator(oneof*/=@|) aliasll='ls-aFls'#Listing aliasla='ls-all' alias..='cd..' alias...='cd../..' exportHISTFILESIZE=5000#Largerhistory exportCLICOLOR=1#Usecolors(ifpossible) exportLSCOLORS=ExGxFxdxCxDxDxBxBxExEx 20.2tcsh 2DCHQDBSR@MCOHODRENQSBRG@MCBRGRHLOKD@MC@QDSGDR@LD@RRG #cmdfile#Redirectbothstdoutandstderrtofile. #cmdfile#Appendbothstdoutandstderrtofile. #cmd1|cmd2#pipestdouttocmd2 #cmd1|cmd2#pipestdoutandstderrtocmd2 4GDRDSSHMFRENQBRGSBRG@QDRDSHM~/.cshrc
  46. 46. QDKN@CVHSGRNTQBDBRGQB%W@LOKDR #in.cshrc aliasls'ls-aF' aliasll'ls-aFls' aliasla'ls-all' alias..'cd..' alias...'cd../..' setprompt=%B%n%b@%B%m%b%/#likeuser@host/path/todir sethistory=5000 setsavehist=(6000merge) setautolist#Reportpossiblecompletionswithtab setvisiblebell#Donotbeep,inversecolors #Bindkeyandcolors bindkey-eSelectEmacsbindings#Useemacskeystoeditthecommandprompt bindkey-kuphistory-search-backward#Useupanddownarrowtosearch bindkey-kdownhistory-search-forward setenvCLICOLOR1#Usecolors(ifpossible) setenvLSCOLORSExGxFxdxCxDxDxBxBxExEx 4GDDL@BRLNCDDM@AKDRSNTRDSGDDL@BRJDXRRGNQSBTSRSNLNCHEXSGDBNLL@MCOQNLOSKHMD 4GHRHRDWSQDLDKXTRDETKMNSNMKXENQDL@BRTRDQR 4GDLNRSTRDCBNLL@MCR@QD # @-NUDBTQRNQSNADFHMMHMFNEKHMD # D-NUDBTQRNQSNDMCNEKHMD - A-NUDBTQRNQA@BJNMDVNQC - E-NUDBTQRNQENQV@QCNMDVNQC - C#TSSGDMDWSVNQC # V#TSSGDK@RSVNQC # T#TSDUDQXSGHMFADENQDSGDBTQRNQ # J#TSDUDQXSGHMF@ESDQSGDBTQRNQQDRSNESGDKHMD # X0@RSDSGDK@RSSGHMFSNADBTSRHLOKXO@RSD # ?5MCN Note:# GNKCBNMSQNK
  47. 47. - GNKCLDS@VGHBGHRTRT@KKXSGD@KSNQDRB@ODJDX c3GDKKRc #pkill-TERM-uwww#KillTERMprocessesownedbywww #fuser-k-TERM-m/home#Killeveryprocessaccessing/home(toumount) )LONQS@MSRHFM@KR@QD HUPG@MFTO INTHMSDQQTOS QUITPTHS KILLMNM B@SBG@AKD
  48. 48. MNM HFMNQ@AKDJHKK TERMRNESV@QDSDQLHM@SHNMRHFM@K 3FILESYSTEM $HRJHMENO [NNSO [$HRJTR@FDO [/ODMDCEHKDRO [-NTMSQDLNTMSO [-NTMS 3-O [-NTMSHL@FDO [TQM)3/O [#QD@SDHL@FDO [-DLNQXCHRJO [$HRJ ODQENQL@MBDO 3.1Permissions #G@MFDODQLHRRHNM@MCNVMDQRGHOVHSGchmod@MCchown4GDCDE@TKSTL@RJB@MADBG@MFDCENQ@KK TRDQRHMDSBOQNEHKDENQ,HMTWNQDSBKNFHMBNMEENQQDD3$4GDCDE@TKSTL@RJHRTRT@KKX4GD TL@RJHRRTASQ@BSDCEQNL
  49. 49. SGTRTL@RJQDRTKSRHM@ODQLHRRHNME 1--xexecute#Mode764=exec/read/write|read/write|read 2-w-write#For:|--Owner--||-Group-||Oth| 4r--read ugo=au=user,g=group,o=others,a=everyone #chmod[OPTION]MODE[,MODE]FILE#MODEisoftheform[ugoa]*([-+=]([rwxXst])) #chmod640/var/log/maillog#Restrictthelog-rw-r----- #chmodu=rw,g=r,o=/var/log/maillog#Sameasabove #chmod-Ro-r/home/*#Recursiveremoveotherreadableforallusers #chmodu+s/path/to/prog#SetSUIDbitonexecutable(knowwhatyoudo!) #find/-perm-u+s-print#FindallprogramswiththeSUIDbit #chownuser:group/path/to/file#Changetheuserandgroupownershipofafile #chgrpgroup/path/to/file#Changethegroupownershipofafile #chmod640`find./-typef-print`#Changepermissionsto640forallfiles #chmod751`find./-typed-print`#Changepermissionsto751foralldirectories 3.2Diskinformation #diskinfo-v/dev/ad2#informationaboutdisk(sector/size)FreeBSD #hdparm-I/dev/sda#informationabouttheIDE/ATAdisk(Linux) #fdisk/dev/ad2#Displayandmanipulatethepartitiontable #smartctl-a/dev/ad2#DisplaythediskSMARTinfo 3.3Boot FreeBSD 4NANNS@MNKCJDQMDKHESGDMDVJDQMDKCNDRMSANNS
  50. 50. RSNOSGDANNS@SCTQHMFSGDBNTMSCNVM #unload #loadkernel.old #boot 3.4Systemmountpoints/Diskusage #mount|column-t#Showmountedfile-systemsonthesystem #df#displayfreediskspaceandmounteddevices #cat/proc/partitions#Showallregisteredpartitions(Linux) cHKD3XRSDLc
  51. 51. Diskusage #du-sh*#Directorysizesaslisting #du-csh#Totaldirectorysizeofthecurrentdirectory #du-ks*|sort-n-r#Sorteverythingbysizeinkilobytes #ls-lSr#Showfiles,biggestlast 3.5Whohaswhichfilesopened 4GHRHRTRDETKSNEHMCNTSVGHBGEHKDHRAKNBJHMF@O@QSHSHNMVGHBGG@RSNADTMLNTMSDC@MCFHUDR@ SXOHB@KDQQNQNE #umount/home/ umount:unmountof/home#umountimpossiblebecauseafileislockinghome failed:Devicebusy FreeBSDandmostUnixes #fstat-f/home#foramountpoint #fstat-pPID#foranapplicationwithPID #fstat-uuser#forausername HMCNODMDCKNFEHKDNQNSGDQNODMDCEHKDR
  52. 52. R@XENQ8NQF #psax|grepXorg|awk'{print$1}' 1252 #fstat-p1252 USERCMDPIDFDMOUNTINUMMODESZ|DVR/W rootXorg1252root/2drwxr-xr-x512r rootXorg1252text/usr216016-rws--x--x1679848r rootXorg12520/var212042-rw-r--r--56987w 4GDEHKDVHSGHMTLHRSGDNMKXEHKDHMU@Q #find-x/var-inum212042 /var/log/Xorg.0.log Linux HMCNODMDCEHKDRNM@LNTMSONHMSVHSGfuserNQlsof #fuser-m/home#Listprocessesaccessing/home #lsof/home COMMANDPIDUSERFDTYPEDEVICESIZENODENAME tcsh29029eedcobacwdDIR0,18122881048587/home/eedcoba(guam:/home) lsof29140eedcobacwdDIR0,18122881048587/home/eedcoba(guam:/home) !ANTS@M@OOKHB@SHNM psax|grepXorg|awk'{print$1}' 3324 #lsof-p3324 COMMANDPIDUSERFDTYPEDEVICESIZENODENAME Xorg3324root0wREG8,65629612492/var/log/Xorg.0.log !ANTS@RHMFKDEHKD #lsof/var/log/Xorg.0.log COMMANDPIDUSERFDTYPEDEVICESIZENODENAME Xorg3324root0wREG8,65629612492/var/log/Xorg.0.log 3.6Mount/remountafilesystem NQDW@LOKDSGDBCQNL)EKHRSDCHMDSBERS@A #mount/cdrom /QEHMCSGDCDUHBDHMCDUNQVHSGCLDRF cHKD3XRSDLc changethevaluesofsoftandhard)EMNSRODBHEHDC
  53. 53. SGDAKNBJR@QDJ4GDFQ@BDODQHNCHRRDSVHSG edquota-tNQDW@LOKD #edquota-ucolin Linux Diskquotasforusercolin(uid1007): Filesystemblockssofthardinodessofthard /dev/sda810810002000100 FreeBSD Quotasforusercolin: /home:kbytesinuse:504184,limits(soft=700000,hard=800000) inodesinuse:1792,limits(soft=0,hard=0) Formanyusers 4GDBNLL@MCedquota-pHRTRDCSNCTOKHB@SD@PTNS@SNNSGDQTRDQRNQDW@LOKDSNCTOKHB@SD@ QDEDQDMBDPTNS@SN@KKTRDQR #edquota-prefuser`awk-F:'$3499{print$1}'/etc/passwd` #edquota-prefuseruser1user2#Duplicateto2users Checks 5RDQRB@MBGDBJSGDHQPTNS@AXRHLOKXSXOHMFquotaSGDEHKDPTNS@TRDQLTRSADQD@C@AKD 2NNS B@MBGDBJ@KKPTNS@R #quota-ucolin#Checkquotaforauser #repquota/home#Fullreportforthepartitionforallusers 20SHELLS -NRS,HMTWCHRSQHATSHNMRTRDSGDA@RGRGDKKVGHKDSGD3$RTRDSBRG
  54. 54. SGDANTQMDRGDKKHRNMKXTRDC ENQRBQHOSRHKSDQR@QDUDQXTRDETK@MCB@MADOHODC grep0@SSDQML@SBGHMF sed3D@QBG@MC2DOK@BDRSQHMFRNQBG@Q@BSDQR cut0QHMSRODBHEHBBNKTLMREQNL@L@QJDQ sort3NQS@KOG@ADSHB@KKXNQMTLDQHB@KKX uniq2DLNUDCTOKHB@SDKHMDREQNL@EHKD NQDW@LOKDTRDC@KK@SNMBD #ifconfig|sed's///g'|cut-d-f1|uniq|grep-E[a-z0-9]+|sort-r #ifconfig|sed'/.*inetaddr:/!d;s///;s/.*//'|sort-t.-k1,1n-k2,2n-k3,3n-k4,4n 4GDEHQRSBG@Q@BSDQHMSGDRDCO@SSDQMHR@S@A4NVQHSD@S@ANMSGDBNMRNKD
  55. 55. TRDBSQK UBSQK S@A 20.1bash 2DCHQDBSR@MCOHODRENQA@RG@MCRG #cmd1file#Redirectstdouttofile. #cmd2file#Redirectstderrtofile. #cmd1file#Redirectandappendstdouttofile. #cmdfile#Redirectbothstdoutandstderrtofile. #cmdfile21#Redirectsstderrtostdoutandthentofile. #cmd1|cmd2#pipestdouttocmd2 #cmd121|cmd2#pipestdoutandstderrtocmd2 -NCHEXXNTQBNMEHFTQ@SHNMHM]A@RGQBHSB@M@KRNAD]A@RG?OQNEHKD 4GDENKKNVHMFDMSQHDR@QD TRDETK
  56. 56. QDKN@CVHSGA@RGQB7HSGBXFVHMTRD]A@RG?OQNEHKDVHSGQWUSO@RSVHSGRGHESKDES BKHBJ c3GDKKRc
  57. 57. Dumpandrestore )SB@MADTRDETKSNCTLO@MCQDRSNQD@M31,HSDC@S@A@RDNQDW@LOKDXNTB@MDCHSSGDCTLOEHKD SNBG@MFD@BNKTLM@SSQHATSDNQSXOD@MCSGDMQDRSNQDSGDC@S@A@RD4GHRHRD@RHDQSG@MLDRRHMF VHSG31,BNLL@MCR5RDSGDBNLL@MCsqlite3ENQ@WC@S@A@RD #sqlitedatabase.db.dumpdump.sql#dump #sqlitedatabase.dbdump.sql#restore Convert2.xto3.xdatabase sqlitedatabase_v2.db.dump|sqlite3database_v3.db 19DISKQUOTA !CHRJPTNS@@KKNVRSNKHLHSSGD@LNTMSNECHRJRO@BD@MCNQSGDMTLADQNEEHKDR@TRDQNQNQ LDLADQNEFQNTO B@MTRD4GDPTNS@R@QD@KKNB@SDCNM@ODQ EHKDRXRSDLA@RHR@MC@QDDMENQBDCAX SGDJDQMDK 19.1Linuxsetup 4GDPTNS@SNNKRO@BJ@FDTRT@KKXMDDCRSNADHMRS@KKDC
  58. 58. HSBNMS@HMRSGDBNLL@MCKHMDSNNKR !BSHU@SDSGDTRDQPTNS@HMSGDERS@A@MCQDLNTMSSGDO@QSHSHNM)ESGDO@QSHSHNMHRATRX
  59. 59. DHSGDQ@KK KNBJDCEHKDRLTRSADBKNRDC
  60. 60. NQSGDRXRSDLLTRSADQDANNSDC!CCusrquotaSNSGDERS@ALNTMS NOSHNMR
  61. 61. ENQDW@LOKD /dev/sda2/homereiserfsrw,acl,user_xattr,usrquota11 #mount-oremount/home #mount#Checkifusrquotaisactive,otherwisereboot )MHSH@KHYDSGDPTNS@TRDQEHKDVHSGquotacheck #quotacheck-vum/home #chmod644/home/aquota.user#Tolettheuserschecktheirownquota !BSHU@SDSGDPTNS@DHSGDQVHSGSGDOQNUHCDCRBQHOSDFDSBHMHSCPTNS@CNM3T3% NQVHSGquotaon quotaon-vu/home #GDBJSG@SSGDPTNS@HR@BSHUDVHSG quota-v 19.2FreeBSDsetup 4GDPTNS@SNNKR@QDO@QSNESGDA@RDRXRSDL
  62. 62. GNVDUDQSGDJDQMDKMDDCRSGDNOSHNMPTNS@)EHSHRMNS SGDQD
  63. 63. @CCHS@MCQDBNLOHKDSGDJDQMDK optionsQUOTA !RVHSG,HMTW
  64. 64. @CCSGDPTNS@SNSGDERS@ANOSHNMRTRDQPTNS@
  65. 65. MNSTRQPTNS@ /dev/ad0s1d/homeufsrw,noatime,userquota22 #mount/home#Toremountthepartition %M@AKDCHRJPTNS@RHMDSBQBBNME@MCRS@QSSGDPTNS@ #grepquotas/etc/rc.conf enable_quotas=YES#turnonquotasonstartup(orNO). check_quotas=YES#Checkquotasonstartup(orNO). #/etc/rc.d/quotastart 19.3Assignquotalimits 4GDPTNS@R@QDMNSKHLHSDCODQCDE@TKSRDSSN 4GDKHLHSR@QDRDSVHSGedquotaENQRHMFKDTRDQR !PTNS@B@MAD@KRNCTOKHB@SDCSNL@MXTRDQR4GDEHKDRSQTBSTQDHRCHEEDQDMSADSVDDMSGDPTNS@ HLOKDLDMS@SHNMR
  66. 66. ATSSGDOQHMBHOKDHRSGDR@LDSGDU@KTDRNEAKNBJR@MCHMNCDRB@MADKHLHSDCOnly c$HRJ1TNS@c FreeBSD #mount-v-tcd9660/dev/cd0c/mnt#cdrom #mount_cd9660/dev/wcd0c/cdrom#othermethod #mount-v-tmsdos/dev/fd0c/mnt#floppy %MSQXHMDSBERS@A #DeviceMountpointFStypeOptionsDumpPass# /dev/acd0/cdromcd9660ro,noauto00 4NKDSTRDQRCNHS #sysctlvfs.usermount=1#Orinsertthelinevfs.usermount=1in/etc/sysctl.conf Linux #mount-tauto/dev/cdrom/mnt/cdrom#typicalcdrommountcommand #mount/dev/hdc-tiso9660-r/cdrom#typicalIDE #mount/dev/scd0-tiso9660-r/cdrom#typicalSCSIcdrom #mount/dev/sdc0-tntfs-3g/windows#typicalSCSI %MSQXHMDSBERS@A /dev/cdrom/media/cdromsubfsnoauto,fs=cdfss,ro,procuid,nosuid,nodev,exec00 MountaFreeBSDpartitionwithLinux HMCSGDO@QSHSHNMMTLADQBNMS@HMHMFVHSGECHRJ
  67. 67. SGHRHRTRT@KKXSGDQNNSO@QSHSHNM
  68. 68. ATSHSBNTKCAD@M NSGDQ3$RKHBDSNN)ESGDQDD3$G@RL@MXRKHBDR
  69. 69. SGDX@QDSGDNMDMNSKHRSDCHMSGDECHRJS@AKD
  70. 70. ATSUHRHAKDHMCDURC@ NQCDUGC@ #fdisk/dev/sda#FindtheFreeBSDpartition /dev/sda3*5357790520474842+a5FreeBSD #mount-tufs-oufstype=ufs2,ro/dev/sda3/mnt /dev/sda10=/tmp;/dev/sda11/usr#Theotherslices Remount 2DLNTMS@CDUHBDVHSGNTSTMLNTMSHMFHS.DBDRR@QXENQERBJENQDW@LOKD #mount-oremount,ro/#Linux #mount-oro-u/#FreeBSD #NOXSGDQ@VC@S@EQNL@BCQNLHMSN@MHRNHL@FDCDE@TKSAKNBJRHYDLHFGSB@TRDOQNAKDLR #ddif=/dev/cd0cof=file.isobs=2048 Virtualbox !KKNV@RG@QDNMSGDGNRS #VBoxManagesharedfolderaddGuestName--nameshare--hostpathC:hostshare -NTMSRG@QDNMFTDRSKHMTW
  71. 71. QDD3$ #sudomount-tvboxsfshare/home/vboxshare#-ouid=1000,gid=1000(asappropriate) share/home/colin/sharevboxsfdefaults,uid=colin00#fstabentry OSX #diskutillist#Listthepartitionsofadisk #diskutilunmountDisk/dev/disk1#Unmountanentiredisk(allvolumes) #chflagshidden~/Documents/folder#Hidefolder(reversewithunhidden) 3.7Addswapon-the-fly 3TOONRDXNTMDDCLNQDRV@OQHFGSMNV
  72. 72. R@X@'EHKDRV@OFA,HMTWNMKX #ddif=/dev/zeroof=/swap2gbbs=1024kcount=2000 #mkswap/swap2gb#createtheswaparea #swapon/swap2gb#activatetheswap.Itnowinuse #swapoff/swap2gb#whendonedeactivatetheswap #rm/swap2gb cHKD3XRSDLc
  73. 73. 3.8MountanSMBshare 3TOONRDVDV@MSSN@BBDRRSGD3-RG@QDLXRG@QDNMSGDBNLOTSDQRLARDQUDQ
  74. 74. SGD@CCQDRR@R SXODCNM@7HMCNVR0#HRRLARDQUDQLXRG@QD7DLNTMSNMLMSRLARG@QD7@QMHMFBHER V@MSR@M)0NQ$.3M@LD
  75. 75. MNS@7HMCNVRM@LD Linux/OSX #smbclient-Uuser-I192.168.16.229-L//smbshare/#Listtheshares #mount-tsmbfs-ousername=winuser//smbserver/myshare/mnt/smbshare #mount-tcifs-ousername=winuser,password=winpwd//192.168.16.229/myshare/mnt/share -NTMC3@LA@RG@QDSGQNTFGRRGSTMMDK #ssh-C-f-N-p20022-L445:127.0.0.1:445me@server#connecton20022,tunnel445 #mount-tsmbfs//colin@localhost/colin~/mnt #mount_smbfs//colin:mypassword@127.0.0.1/private/Volumes/private#IusethisonOSX+ssh !CCHSHNM@KKXVHSGSGDO@BJ@FDLNTMSBHERHSHRONRRHAKDSNRSNQDSGDBQDCDMSH@KRHM@EHKD
  76. 76. ENQDW@LOKD /home/user/.smb username=winuser password=winpwd !MCLNTMS@RENKKNV #mount-tcifs-ocredentials=/home/user/.smb//192.168.16.229/myshare/mnt/smbshare FreeBSD 5RD )SNFHUDSGD)0NQ$.3M@LD RLARDQUDQHRSGD7HMCNVRM@LD #smbutilview-I192.168.16.229//winuser@smbserver#Listtheshares #mount_smbfs-I192.168.16.229//winuser@smbserver/myshare/mnt/smbshare 3.9Mountanimage #hdiutilmountimage.iso#OSX Linuxloop-back #mount-tiso9660-oloopfile.iso/mnt#MountaCDimage #mount-text3-oloopfile.img/mnt#Mountanimagewithext3fs FreeBSD 7HSGLDLNQXCDUHBDCNJKCKN@CLCJNHEMDBDRR@QX #mdconfig-a-tvnode-ffile.iso-u0 #mount-tcd9660/dev/md0/mnt #umount/mnt;mdconfig-d-u0#Cleanupthemddevice /QVHSGUHQST@KMNCD #vnconfig/dev/vn0cfile.iso;mount-tcd9660/dev/vn0c/mnt #umount/mnt;vnconfig-u/dev/vn0c#Cleanupthevndevice SolarisandFreeBSD VHSGKNNO A@BJEHKDHMSDQE@BDNQKNEH #lofiadm-afile.iso #mount-Fhsfs-oro/dev/lofi/1/mnt #umount/mnt;lofiadm-d/dev/lofi/1#Cleanupthelofidevice 3.10CreateandburnanISOimage 4GHRVHKKBNOXSGDBCNQ$6$RDBSNQENQRDBSNQ7HSGNTSconv=notrunc
  77. 77. SGDHL@FDVHKKADRL@KKDQHE SGDQDHRKDRRBNMSDMSNMSGDBC3DDADKNV@MCSGDCCDW@LOKDRO@FD #ddif=/dev/hdcof=/tmp/mycd.isobs=2048conv=notrunc cHKD3XRSDLc 18.2MySQL Changemysqlrootorusernamepassword Method1 #/etc/init.d/mysqlstop or #killallmysqld #mysqld--skip-grant-tables #mysqladmin-urootpassword'newpasswd' #/etc/init.d/mysqlstart Method2 #mysql-urootmysql mysqlUPDATEUSERSETPASSWORD=PASSWORD(newpassword)whereuser='root'; mysqlFLUSHPRIVILEGES;#Useusernameinsteadofroot mysqlquit Createuseranddatabase(seeMySQLdoc ) #mysql-urootmysql mysqlCREATEUSER'bob'@'localhost'IDENTIFIEDBY'pwd';#createonlyauser mysqlCREATEDATABASEbobdb; mysqlGRANTALLON*.*TO'bob'@'%'IDENTIFIEDBY'pwd';#Uselocalhostinsteadof% #torestrictthenetworkaccess mysqlDROPDATABASEbobdb;#Deletedatabase mysqlDROPUSERbob;#Deleteuser mysqlDELETEFROMmysql.userWHEREuser='bobandhost='hostname';#Alt.command mysqlFLUSHPRIVILEGES; Grantremoteaccess 2DLNSD@BBDRRHRSXOHB@KKXODQLHSSDCENQ@C@S@A@RD
  78. 78. @MCMNS@KKC@S@A@RDR4GDEHKD/etc/my.cnf BNMS@HMRSGD)0@CCQDRRSNAHMCSN/MQDD3$my.cnfMNSBQD@SDCODQEDC@TKS
  79. 79. BNOXNMD.cnf EHKDEQNL/usr/local/share/mysqlSN/usr/local/etc/my.cnf 4XOHB@KKXBNLLDMSSGDKHMDbind- address=NTS #mysql-urootmysql mysqlGRANTALLONbobdb.*TObob@'xxx.xxx.xxx.xxx'IDENTIFIEDBY'PASSWORD'; mysqlREVOKEGRANTOPTIONONfoo.*FROMbar@'xxx.xxx.xxx.xxx'; mysqlFLUSHPRIVILEGES;#Use'hostname'oralso'%'forfullaccess Backupandrestore @BJTO@MCQDRSNQD@RHMFKDC@S@A@RD #mysqldump-uroot-psecret--add-drop-databasedbnamedbname_sql.dump #mysql-uroot-psecret-Ddbnamedbname_sql.dump @BJTO@MCQDRSNQD@KKC@S@A@RDR #mysqldump-uroot-psecret--add-drop-database--all-databasesfull.dump #mysql-uroot-psecretfull.dump (DQDHRRDBQDSSGDLXRPKQNNSO@RRVNQC
  80. 80. SGDQDHRMNRO@BD@ESDQ O7GDMSGD ONOSHNMHRTRDC @KNMDVNO@RRVNQC
  81. 81. SGDO@RRVNQCHR@RJDC@SSGDBNLL@MCOQNLOS 18.3SQLite 31,HSD HR@RL@KKONVDQETKRDKE BNMS@HMDC
  82. 82. RDQUDQKDRR
  83. 83. YDQN BNMEHFTQ@SHNM31,C@S@A@RD GSSOCDULXRPKBNLCNBQDEL@MDM@CCHMF TRDQRGSLK GSSOVVVRPKHSDNQF c$@S@A@RDRc
  84. 84. #lprm-#Removeallusersjobsondefaultprinter #lprm-Php45003186#Removejob3186.Findjobnbrwithlpq #lpcstatus#Listallavailableprinters #lpcstatushp4500#Checkifprinterisonlineandqueuelength 3NLDCDUHBDR@QDMNSONRSRBQHOS@MCVHKKOQHMSF@QA@FDVGDMEDCVHSG@OCEEHKD4GHRLHFGSADRNKUDC VHSG #gs-dSAFER-dNOPAUSE-sDEVICE=deskjet-sOutputFile=|lprfile.pdf 0QHMSSN@0$EHKDDUDMHESGD@OOKHB@SHNMCNDRMNSRTOONQSHS5RDgsNMSGDOQHMSBNLL@MCHMRSD@C NElpr #gs-q-sPAPERSIZE=a4-dNOPAUSE-dBATCH-sDEVICE=pdfwrite-sOutputFile=/path/file.pdf 18DATABASES 18.1PostgreSQL Changerootorausernamepassword #psql-dtemplate1-Upgsql alteruserpgsqlwithpassword'pgsql_password';#Useusernameinsteadofpgsql Createuseranddatabase 4GDBNLL@MCRcreateuser
  85. 85. dropuser
  86. 86. createdb@MCdropdb@QDBNMUDMHDMSRGNQSBTSRDPTHU@KDMS SNSGD31,BNLL@MCR4GDMDVTRDQHRANAVHSGC@S@A@RDANACATRD@RQNNSVHSGOFRPKSGD C@S@A@RDRTODQTRDQ #createuser-Upgsql-Pbob#-Pwillaskforpassword #createdb-Upgsql-Obobbobdb#newbobdbisownedbybob #dropdbbobdb#Deletedatabasebobdb #dropuserbob#Deleteuserbob 4GDFDMDQ@KC@S@A@RD@TSGDMSHB@SHNMLDBG@MHRLHRBNMEHFTQDCHMOF?GA@BNME Grantremoteaccess 4GDEHKD$PGSQL_DATA_D/postgresql.confRODBHEHDRSGD@CCQDRRSNAHMCSN4XOHB@KKX listen_addresses='*'ENQ0NRSFQDRW 4GDEHKD$PGSQL_DATA_D/pg_hba.confCDEHMDRSGD@BBDRRBNMSQNK%W@LOKDR #TYPEDATABASEUSERIP-ADDRESSIP-MASKMETHOD hostbobdbbob212.117.81.42255.255.255.255password hostallall0.0.0.0/0password Backupandrestore 4GDA@BJTOR@MCQDRSNQD@QDCNMDVHSGSGDTRDQOFRPKNQONRSFQDR@BJTO@MCQDRSNQD@RHMFKD C@S@A@RD #pg_dump--cleandbnamedbname_sql.dump #psqldbnamedbname_sql.dump @BJTO@MCQDRSNQD@KKC@S@A@RDRHMBKTCHMFTRDQR #pg_dumpall--cleanfull.dump #psql-ffull.dumppostgres )MSGHRB@RDSGDQDRSNQDHRRS@QSDCVHSGSGDC@S@A@RDONRSFQDRVGHBGHRADSSDQVGDMQDKN@CHMF@M DLOSXBKTRSDQ c$@S@A@RDRc 5RDLJHRNERSNBQD@SD@#$$6$HL@FDEQNLEHKDRHM@CHQDBSNQX4NNUDQBNLDSGDEHKDM@LDR QDRSQHBSHNMR QDM@AKDRSGD2NBJ2HCFDDWSDMRHNMRBNLLNMSN5.)8RXRSDLR
  87. 87. *DM@AKDR*NKHDS DWSDMRHNMRTRDCAX-HBQNRNESRXRSDLR ,@KKNVR)3/EHKDM@LDRSNADFHMVHSG@ODQHNC #mkisofs-J-L-r-VTITLE-oimagefile.iso/path/to/dir #hdiutilmakehybrid-iso-joliet-odir.isodir/#OSX /MQDD3$
  88. 88. LJHRNERHRENTMCHMSGDONQSRHMRXRTSHKRBCQSNNKR BurnaCD/DVDISOimage FreeBSD QDD3$CNDRMNSDM@AKD$-!NM!4!0)CQHUDRAXCDE@TKS$-!HRDM@AKDCVHSGSGDRXRBSKBNLL@MC @MCSGD@QFTLDMSRADKNV
  89. 89. NQVHSGANNSKN@CDQBNMEVHSGSGDENKKNVHMFDMSQHDR hw.ata.ata_dma=1 hw.ata.atapi_dma=1 5RDburncdVHSG@M!4!0)CDUHBDburncdHRO@QSNESGDA@RDRXRSDL @MCcdrecordHMRXRTSHKR BCQSNNKR VHSG@3#3)CQHUD #burncd-f/dev/acd0dataimagefile.isofixate#ForATAPIdrive #cdrecord-scanbus#Tofindtheburnerdevice(like1,0,0) #cdrecorddev=1,0,0imagefile.iso Linux !KRNTRDcdrecordVHSG,HMTW@RCDRBQHADC@ANUD!CCHSHNM@KKXHSHRONRRHAKDSNTRDSGDM@SHUD!4!0) HMSDQE@BDVGHBGHRENTMCVHSG #cdrecorddev=ATAPI-scanbus !MCATQMSGD#$$6$@R@ANUD dvd+rw-tools 4GDCUCQV SNNKRO@BJ@FDQDD3$ONQSRRXRTSHKRCUCQV SNNKR B@MCNHS@KK@MCHMBKTCDR growisofsSNATQM#$RNQ$6$R4GDDW@LOKDRQDEDQSNSGDCUCCDUHBD@R/dev/dvdVGHBGBNTKC AD@RXLKHMJSN/dev/scd0SXOHB@KRBRHNM,HMTW NQ/dev/cd0SXOHB@KQDD3$ NQ/dev/rcd0c SXOHB@K.DS3$/ODM3$BG@Q@BSDQ3#3) NQ/dev/rdsk/c0t1d0s23NK@QHRDW@LOKDNE@BG@Q@BSDQ 3#3)!4!0)#$ 2/-CDUHBD 4GDQDHR@MHBDCNBTLDMS@SHNMVHSGDW@LOKDRNMSGDQDD3$ G@MCANNJBG@OSDQ #-dvd-compatclosesthedisk #growisofs-dvd-compat-Z/dev/dvd=imagefile.iso#Burnexistingisoimage #growisofs-dvd-compat-Z/dev/dvd-J-R/p/to/data#Burndirectly ConvertaNero.nrgfileto.iso .DQNRHLOKX@CCR@+AGD@CDQSN@MNQL@KHRNHL@FD4GHRB@MADSQHLLDCVHSGCC #ddbs=1kif=imagefile.nrgof=imagefile.isoskip=300 Convertabin/cueimageto.iso 4GDKHSSKDbchunkOQNFQ@L B@MCNSGHR)SHRHMSGDQDD3$ONQSRHMRXRTSHKRABGTMJ #bchunkimagefile.binimagefile.cueimagefile.iso 3.11Createafilebasedimage NQDW@LOKD@O@QSHSHNMNE'TRHMFSGDEHKDTRQUCHRJHLF(DQDVDTRDSGDUMNCD
  90. 90. ATSHSBNTKC @KRNAD FreeBSD #ddif=/dev/randomof=/usr/vdisk.imgbs=1Kcount=1M #mdconfig-a-tvnode-f/usr/vdisk.img-u0#Createsdevice/dev/md1 #bsdlabel-w/dev/md0 GSSOVVVEQDDARCNQFG@MCANNJBQD@SHMF CUCRGSLK GSSOEQDRGLD@SMDSOQNIDBSRABGTMJ cHKD3XRSDLc
  91. 91. #newfs/dev/md0c #mount/dev/md0c/mnt #umount/mnt;mdconfig-d-u0;rm/usr/vdisk.img#Cleanupthemddevice 4GDEHKDA@RDCHL@FDB@MAD@TSNL@SHB@KKXLNTMSDCCTQHMFANNSVHSG@MDMSQXHMDSBQBBNME@MC DSBERS@A4DRSXNTQRDSTOVHSG#/etc/rc.d/mdconfigstartEHQRSCDKDSDSGDLCCDUHBDVHSG# mdconfig-d-u0 .NSDGNVDUDQSG@SSGHR@TSNL@SHBRDSTOVHKKNMKXVNQJHESGDEHKDHL@FDHR./4NMSGDQNNSO@QSHSHNM 4GDQD@RNMHRSG@SSGDDSBQBCLCBNMEHFRBQHOSHRDWDBTSDCUDQXD@QKXCTQHMFANNS@MCSGDQNNS O@QSHSHNMHRRSHKKQD@C NMKX)L@FDRKNB@SDCNTSRHCDSGDQNNSO@QSHSHNMVHKKADLNTMSDCK@SDQVHSGSGD RBQHOSDSBQBCLCBNMEHF ANNSKN@CDQBNME md_load=YES DSBQBBNME #mdconfig_md0=-tvnode-f/usr/vdisk.img#/usrisnotontherootpartition DSBERS@A4GD@SSGDDMCHRHLONQS@MS
  92. 92. HSSDKKERBJSNHFMNQDSGHRCDUHBD
  93. 93. @RHRCNDRMNSDWHRS XDS /dev/md0/usr/vdiskufsrw00 )SHR@KRNONRRHAKDSNHMBQD@RDSGDRHYDNESGDHL@FD@ESDQV@QC
  94. 94. R@XENQDW@LOKD-K@QFDQ #umount/mnt;mdconfig-d-u0 #ddif=/dev/zerobs=1mcount=300/usr/vdisk.img #mdconfig-a-tvnode-f/usr/vdisk.img-u0 #growfs/dev/md0 #mount/dev/md0c/mnt#Filepartitionisnow300MBlarger Linux #ddif=/dev/zeroof=/usr/vdisk.imgbs=1024kcount=1024 #mkfs.ext3/usr/vdisk.img #mount-oloop/usr/vdisk.img/mnt #umount/mnt;rm/usr/vdisk.img#Cleanup Linuxwithlosetup /dev/zeroHRLTBGE@RSDQSG@Murandom
  95. 95. ATSKDRRRDBTQDENQDMBQXOSHNM #ddif=/dev/urandomof=/usr/vdisk.imgbs=1024kcount=1024 #losetup/dev/loop0/usr/vdisk.img#Createsandassociates/dev/loop0 #mkfs.ext3/dev/loop0 #mount/dev/loop0/mnt #losetup-a#Checkusedloops #umount/mnt #losetup-d/dev/loop0#Detach #rm/usr/vdisk.img 3.12Createamemoryfilesystem !LDLNQXA@RDCEHKDRXRSDLHRUDQXE@RSENQGD@UX)/@OOKHB@SHNM(NVSNBQD@SD@-O@QSHSHNM LNTMSDCNMLDLCHRJ FreeBSD #mount_mfs-orw-s64Mmd/memdisk #umount/memdisk;mdconfig-d-u0#Cleanupthemddevice md/memdiskmfsrw,-s64M00#/etc/fstabentry Linux #mount-ttmpfs-osize=64mtmpfs/memdisk cHKD3XRSDLc #NMUDQS5MHWSN$/3MDVKHMDRwithinaWindowsenvironment5RDRDCNQ@VJEQNLLHMFVNQ BXFVHM #sed-npunixfile.txtdosfile.txt #awk1unixfile.txtdosfile.txt#UNIXtoDOS(withacygwinshell) 2DLNUD^ML@BMDVKHMD@MCQDOK@BDVHSGTMHWMDVKHMD4NFDS@^MTRD#4, 6SGDM#4, - #tr'^M''n'macfile.txt 16.3PDFtoJpegandconcatenatePDFfiles #NMUDQS@0$CNBTLDMSVHSGgs'GNRS3BQHOS SNIODFNQOMF HL@FDRENQD@BGO@FD!KRNLTBG RGNQSDQVHSGconvert@MCmogrifyEQNL)L@FD-@FHBJNQ'Q@OGHBR-@FHBJ #gs-dBATCH-dNOPAUSE-sDEVICE=jpeg-r150-dTextAlphaBits=4-dGraphicsAlphaBits=4 -dMaxStripSize=8192-sOutputFile=unixtoolbox_%d.jpgunixtoolbox.pdf #convertunixtoolbox.pdfunixtoolbox-%03d.png #convert*.jpegimages.pdf#CreateasimplePDFwithallpictures #convertimage000*-resample120x120-compressJPEG-quality80images.pdf #mogrify-formatpng*.ppm#convertallppmimagestopngformat 'GNRSRBQHOSB@M@KRNBNMB@SDM@SDLTKSHOKDOCEEHKDRHMSN@RHMFKDNMD4GHRNMKXVNQJRVDKKHESGD0$ EHKDR@QDVDKKADG@UDC #gs-q-sPAPERSIZE=a4-dNOPAUSE-dBATCH-sDEVICE=pdfwrite-sOutputFile=all.pdf file1.pdffile2.pdf...#OnWindowsuse'#'insteadof'=' %WSQ@BSHL@FDREQNLOCECNBTLDMSTRHMFpdfimagesEQNLONOOKDQNQxpdf #pdfimagesdocument.pdfdst/#extractallimagesandputindst #yuminstallpoppler-utils#installpoppler-utilsifneeded.or: #apt-getinstallpoppler-utils 16.4Convertvideo #NLOQDRRSGD#@MNMCHFHB@LUHCDNVHSG@MLODFBNCDB@MCQDO@HQSGDBQ@OOXRNTMC #mencoder-ovideoout.avi-oacmp3lame-ovclavc-srate11025 -channels1-af-advforce=1-lameoptspreset=medium-lavcopts vcodec=msmpeg4v2:vbitrate=600-mc0vidoein.AVI 3DDRNWENQRNTMCOQNBDRRHMF 16.5Copyanaudiocd 4GDOQNFQ@Lcdparanoia B@MR@UDSGD@TCHNSQ@BJRQDD3$ONQSHM@TCHNBCO@Q@MNH@
  96. 96. oggenc B@MDMBNCDHM/FF6NQAHRENQL@S
  97. 97. lameBNMUDQSRSNLO #cdparanoia-B#Copythetrackstowavfilesincurrentdir #lame-b256in.wavout.mp3#Encodeinmp3256kb/s #foriin*.wav;dolame-b256$i`basename$i.wav`.mp3;done #oggencin.wav-b256out.ogg#EncodeinOggVorbis256kb/s 17PRINTING 17.1Printwithlpr #lprunixtoolbox.ps#Printondefaultprinter #exportPRINTER=hp4600#Changethedefaultprinter #lpr-Php4500#2unixtoolbox.ps#Useprinterhp4500andprint2copies #lpr-oDuplex=DuplexNoTumble...#Printduplexalongthelongside #lpr-oPageSize=A4,Duplex=DuplexNoTumble... #lpq#Checkthequeueondefaultprinter #lpq-l-Php4500#Queueonprinterhp4500withverbose GSSOENNK@ARBNLWOCECNVMKN@CGSLK GSSOWHOGNQFO@Q@MNH@ c0QHMSHMFc
  98. 98. #cd/usr/ports/net/rsync/#Selectthepackagetoinstall #makeinstalldistclean#Installandcleanup(alsoseemanports) #makepackage#Makeabinarypackageofthisport #pkgdb-F#Fixthepackageregistrydatabase #portsclean-C-DD#Cleanworkdiranddistdir(partofportupgrade) OSXMacPorts (usesudoforallcommands) #portselfupdate#Updatetheporttree(safe) #portinstalled#Listinstalledports #portdepsapache2#Listdependenciesforthisport #portsearchpgrep#Searchforstring #portinstallproctools#Installthispackage #portvariantsghostscript#Listvariantsofthisport #port-vinstallghostscript+no_x11#-no_x11fornegativevalue #portclean--allghostscript#Cleanworkdirofport #portupgradeghostscript#Upgradethisport #portuninstallghostscript#Uninstallthisport #port-funinstallinstalled#Uninstalleverything 15.3Librarypath $TDSNBNLOKDWCDODMCDMBHDR@MCQTMSHLDKHMJHMF
  99. 99. OQNFQ@LR@QDCHEEHBTKSSNBNOXSN@MNSGDQRXRSDL NQCHRSQHATSHNM(NVDUDQENQRL@KKOQNFQ@LRVHSGKHSSKDCDODMCDMBHDR
  100. 100. SGDLHRRHMFKHAQ@QHDRB@MAD BNOHDCNUDQ4GDQTMSHLDKHAQ@QHDR@MCSGDLHRRHMFNMD @QDBGDBJDCVHSGldd@MCL@M@FDCVHSG ldconfig #ldd/usr/bin/rsync#Listallneededruntimelibraries #otool-L/usr/bin/rsync#OSXequivalenttoldd #ldconfig-n/path/to/libs/#Addapathtothesharedlibrariesdirectories #ldconfig-m/path/to/libs/#FreeBSD #LD_LIBRARY_PATH#Thevariablesetthelinklibrarypath 16CONVERTMEDIA 3NLDSHLDRNMDRHLOKXMDDCSNBNMUDQS@UHCDN
  101. 101. @TCHNEHKDNQCNBTLDMSSN@MNSGDQENQL@S 16.1Textencoding 4DWSDMBNCHMFB@MFDSSNS@KKXVQNMF
  102. 102. RODBH@KKXVGDMSGDK@MFT@FDQDPTHQDRRODBH@KBG@Q@BSDQRKHJD ^_`4GDBNLL@MCiconvB@MBNMUDQSEQNLNMDDMBNCHMFSN@MNSGDQ #iconv-ffrom_encoding-tto_encodinginput_file #iconv-fISO8859-1-tUTF-8-ofile.inputfile_utf8 #iconv-l#Listknowncodedcharactersets 7HSGNTSSGD ENOSHNM
  103. 103. HBNMUVHKKTRDSGDKNB@KBG@Q RDS
  104. 104. VGHBGHRTRT@KKXEHMDHESGDCNBTLDMSCHROK@XR VDKK #NMUDQSEHKDM@LDREQNLNMDDMBNCHMFSN@MNSGDQMNSEHKDBNMSDMS 7NQJR@KRNHENMKXRNLDEHKDR@QD @KQD@CXTSE #convmv-r-futf8--nfd-tutf8--nfc/dir/*--notest 16.2Unix-DOSnewlines #NMUDQS$/3#2, SN5MHW, MDVKHMDR@MCA@BJwithinaUnixshell3DD@KRNdos2unix@MC unix2dosHEXNTG@UDSGDL #sed's/.$//'dosfile.txtunixfile.txt#DOStoUNIX #awk'{sub(/r$/,);print}'dosfile.txtunixfile.txt#DOStoUNIX #awk'{sub(/$/,r);print}'unixfile.txtdosfile.txt#UNIXtoDOS GSSOFTHCDL@BONQSRNQF c#NMUDQS-DCH@c 3.13Diskperformance 2D@C@MCVQHSD@'EHKDNMO@QSHSHNM@CRBGNLD #timeddif=/dev/ad4s3cof=/dev/nullbs=1024kcount=1000 #timeddif=/dev/zerobs=1024kcount=1000of=/home/1Gb.file #hdparm-tT/dev/hda#Linuxonly 4NETWORK 2NTSHMFO [!CCHSHNM@K)0O [#G@MFD-!#O [0NQSRO [HQDV@KKO [)0NQV@QC O [.!4O [$.3O [$(#0O [4Q@EEHBO [1N3O [.)3O [.DSB@SO 4.1Debugging(SeealsoTrafficanalysis)(page20) Linux #ethtooleth0#Showtheethernetstatus(replacesmii-diag) #ethtool-seth0speed100duplexfull#Force100MbitFullduplex #ethtool-seth0autonegoff#Disableautonegotiation #ethtool-peth1#Blinktheethernetled-veryusefulwhensupported #iplinkshow#DisplayallinterfacesonLinux(similartoifconfig) #iplinkseteth0up#Bringdeviceup(ordown).Sameasifconfigeth0up #ipaddrshow#DisplayallIPaddressesonLinux(similartoifconfig) #ipneighshow#Similartoarp-a OtherOSes #ifconfigfxp0#CheckthemediafieldonFreeBSD #arp-a#Checktherouter(orhost)ARPentry(allOS) #pingcb.vu#Thefirstthingtotry... #traceroutecb.vu#Printtheroutepathtodestination #ifconfigfxp0media100baseTXmediaoptfull-duplex#100Mbitfullduplex(FreeBSD) #netstat-s#System-widestatisticsforeachnetworkprotocol !CCHSHNM@KBNLL@MCRVGHBG@QDMNS@KV@XRHMRS@KKDCODQCDE@TKSATSD@RXSNEHMC #arping192.168.16.254#Pingonethernetlayer #tcptraceroute-f5cb.vu#usestcpinsteadoficmptotracethroughfirewalls 4.2Routing Printroutingtable #route-n#Linuxoruseiproute #netstat-rn#Linux,BSDandUNIX #routeprint#Windows Addanddeletearoute FreeBSD #routeadd212.117.0.0/16192.168.1.1 #routedelete212.117.0.0/16 #routeadddefault192.168.1.1 !CCSGDQNTSDODQL@MDMSKXHMDSBQBBNME static_routes=myroute route_myroute=-net212.117.0.0/16192.168.1.1 Linux #routeadd-net192.168.20.0netmask255.255.255.0gw192.168.16.254 #iprouteadd192.168.20.0/24via192.168.16.254#sameasabovewithiproute #routeadd-net192.168.20.0netmask255.255.255.0deveth0 #routeadddefaultgw192.168.51.254 c.DSVNQJc
  105. 105. #iprouteadddefaultvia192.168.51.254deveth0#sameasabovewithiproute #routedelete-net192.168.20.0netmask255.255.255.0 Solaris #routeadd-net192.168.20.0-netmask255.255.255.0192.168.16.254 #routeadddefault192.168.51.2541#1=hopstothenextgateway #routechangedefault192.168.50.2541 0DQL@MDMSDMSQHDR@QDRDSHMDMSQXHM/etc/defaultrouter Windows #Routeadd192.168.50.0mask255.255.255.0192.168.51.253 #Routeadd0.0.0.0mask0.0.0.0192.168.51.254 5RD@CC OSNL@JDSGDQNTSDODQRHRSDMS 4.3ConfigureadditionalIPaddresses Linux #ifconfigeth0192.168.50.254netmask255.255.255.0#FirstIP #ifconfigeth0:0192.168.51.254netmask255.255.255.0#SecondIP #ipaddradd192.168.50.254/24deveth0#Equivalentipcommands #ipaddradd192.168.51.254/24deveth0labeleth0:1 FreeBSD #ifconfigfxp0inet192.168.50.254/24#FirstIP #ifconfigfxp0alias192.168.51.254netmask255.255.255.0#SecondIP #ifconfigfxp0-alias192.168.51.254#RemovesecondIPalias 0DQL@MDMSDMSQHDRHMDSBQBBNME ifconfig_fxp0=inet192.168.50.254netmask255.255.255.0 ifconfig_fxp0_alias0=192.168.51.254netmask255.255.255.0 Solaris #GDBJSGDRDSSHMFRVHSGifconfig-a #ifconfighme0plumb#Enablethenetworkcard #ifconfighme0192.168.50.254netmask255.255.255.0up#FirstIP #ifconfighme0:1192.168.51.254netmask255.255.255.0up#SecondIP 4.4ChangeMACaddress .NQL@KKXXNTG@UDSNAQHMFSGDHMSDQE@BDCNVMADENQDSGDBG@MFD$NMSSDKKLDVGXXNTV@MSSN BG@MFDSGD-!#@CCQDRR #ifconfigeth0down #ifconfigeth0hwether00:01:02:03:04:05#Linux #ifconfigfxp0link00:01:02:03:04:05#FreeBSD #ifconfighme0ether00:01:02:03:04:05#Solaris #sudoifconfigen0ether00:01:02:03:04:05#OSXTiger,SnowLeopardLAN* #sudoifconfigen0lladdr00:01:02:03:04:05#OSXLeopard 4XOHB@KVHQDKDRRHMSDQE@BDHRen1@MCMDDCRCNCHR@RRNBH@SDEQNL@MXMDSVNQJEHQRSNRWC@HKX GNVSN #echoaliasairport='/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport' ~/.bash_profile#orsymlinkto/usr/sbin #airport-z#Disassociatefromwirelessnetworks #airport-I#Getinfofromwirelessnetwork -@MXSNNKRDWHRSENQ7HMCNVRNQDW@LOKDDSGDQBG@MFD /QKNNJENQ-@B-@JDTO
  106. 106. RL@B GSSOMSRDBTQHSXMTSNNKANWDSGDQBG@MFD c.DSVNQJc exporthttp_proxy=http://proxy_server:3128 exportftp_proxy=http://proxy_server:3128 15.1Listinstalledpackages #rpm-qa#Listinstalledpackages(RH,SuSE,RPMbased) #dpkg-l#Debian,Ubuntu #pkg_info#FreeBSDlistallinstalledpackages #pkg_info-Wsmbd#FreeBSDshowwhichpackagesmbdbelongsto #pkginfo#Solaris 15.2Add/removesoftware QNMSDMCRX@RSX@RSENQ3T3%
  107. 107. QDCG@S BNMEHF O@BJ@FDRENQ2DC(@S #rpm-ipkgname.rpm#installthepackage(RH,SuSE,RPMbased) #rpm-epkgname#Removepackage SuSEzypper(seedocandcheetsheet) #zypperrefresh#Refreshrepositorie #zypperinstallvim#Installthepackagevim #zypperremovevim#Removethepackagevim #zyppersearchvim#Searchpackageswithvim #zypperupdatevim#Searchpackageswithvim Debian #apt-getupdate#Firstupdatethepackagelists #apt-getinstallemacs#Installthepackageemacs #dpkg--removeemacs#Removethepackageemacs #dpkg-Sfile#findwhatpackageafilebelongsto Gentoo 'DMSNNTRDRDLDQFD@RSGDGD@QSNEHSR0NQS@FDO@BJ@FDL@M@FDLDMSRXRSDL #emerge--sync#Firstsyncthelocalportagetree #emerge-upackagename#Installorupgradeapackage #emerge-Cpackagename#Removethepackage #revdep-rebuild#Repairdependencies Solaris 4GDBCQNLO@SGHRTRT@KKX/cdrom/cdrom0 #pkgadd-dcdrom/Solaris_9/ProductSUNWgtar #pkgadd-dSUNWgtar#Adddownloadedpackage(bunzip2first) #pkgrmSUNWgtar#Removethepackage FreeBSD #pkg_add-rrsync#Fetchandinstallrsync. #pkg_delete/var/db/pkg/rsync-xx#Deletethersyncpackage 3DSVGDQDSGDO@BJ@FDR@QDEDSBGDCEQNLVHSGSGDPACKAGESITEU@QH@AKDNQDW@LOKD #exportPACKAGESITE=ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages/Latest/ #orftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/Latest/ FreeBSDports 4GDONQSSQDD/usr/ports/HR@BNKKDBSHNMNERNESV@QDQD@CXSNBNLOHKD@MCHMRS@KKRDDL@MONQSR 4GDONQSR@QDTOC@SDCVHSGSGDOQNFQ@Lportsnap #portsnapfetchextract#Createthetreewhenrunningthefirsttime #portsnapfetchupdate#Updatetheporttree GSSODMNODMRTRDNQF3$:XOODQ?TR@FD GSSOVVVEQDDARCNQFG@MCANNJONQSRGSLK c)MRS@KK3NESV@QDc
  108. 108. #find/-name*.core|xargsrm#Findcoredumpsanddeletethem(alsotrycore.*) #find/-name*.core-print-execrm{};#Othersyntax #Findimagesandcreateanarchive,inameisnotcasesensitive.-rforappend #find.(-iname*.png-o-iname*.jpg)-print-exectar-rfimages.tar{}; #find.-typef-name*.txt!-nameREADME.txt-print#ExcludeREADME.txtfiles #find/var/-size+10M-execls-lh{};#Findlargefiles10MB #find/var/-size+10M-ls#Thisissimpler #find.-size+10M-size-50M-print #find/usr/ports/-namework-typed-print-execrm-rf{};#Cleantheports #FindfileswithSUID;thosefilearevulnerableandmustbekeptsecure #find/-typef-userroot-perm-4000-execls-l{}; #findflac/-iname*.flac-print-size+500k-exec/Applications/Fluke.app/Contents/MacOS/Fluke{}; #IuseabovetoaddflacfilestoiTunesonOSX DB@QDETKVHSGW@QFNQDWDB@RHSLHFGSNQLHFGSMNSGNMNQPTNSHMFR@MCB@MQDSTQMVQNMFQDRTKSR VGDMEHKDRNQCHQDBSNQHDRBNMS@HMRO@BDR)MCNTASTRD OQHMS[W@QFR HMRSD@CNE[W@QFR4GD NOSHNM OQHMSLTRSADSGDK@RSHMSGDEHMCBNLL@MC3DDSGHRMHBDLHMHSTSNQH@KENQEHMC #find.-typef|xargsls-l#Willnotworkwithspacesinnames #find.-typef-print0|xargs-0ls-l#Willworkwithspacesinnames #find.-typef-execls-l'{}';#Orusequotes'{}'with-exec $TOKHB@SDCHQDBSNQXSQDD #find.-typed-execmkdir-p/tmp/new_dest/{}; 14.9Miscellaneous #whichcommand#Showfullpathnameofcommand #timecommand#Seehowlongacommandtakestoexecute #timecat#Usetimeasstopwatch.Ctrl-ctostop #set|grep$USER#Listthecurrentenvironment #cal-3#Displayathreemonthcalendar #date[-u|--utc|--universal][MMDDhhmm[[CC]YY][.ss]] #date10022155#Setdateandtime #whatisgrep#Displayashortinfoonthecommandorword #whereisjava#Searchpathandstandarddirectoriesforword #setenvvarnamevalue#Setenv.variablevarnametovalue(csh/tcsh) #exportvarname=value#setenv.variablevarnametovalue(sh/ksh/bash) #pwd#Printworkingdirectory #mkdir-p/path/to/dir#noerrorifexisting,makeparentdirsasneeded #mkdir-pproject/{bin,src,obj,doc/{html,man,pdf},debug/some/more/dirs} #rmdir/path/to/dir#Removedirectory #rm-rf/path/to/dir#Removedirectoryanditscontent(force) #rm---badchar.txt#Removefilewhitchstartswithadash(-) #cp-la/dir1/dir2#Archiveandhardlinkfilesinsteadofcopy #cp-lpR/dir1/dir2#SameforFreeBSD #cpunixtoolbox.xhtml{,.bak}#Shortwaytocopythefilewithanewextension #mv/dir1/dir2#Renameadirectory #ls-1#listonefileperline #history|tail-50#Displaythelast50usedcommands #cd-#cdtoprevious($OLDPWD)directory #/bin/ls|grep-v.py|xargsrm-r#pipefilenamestormwithxargs #GDBJEHKDG@RGDRVHSGNODMRRK4GHRHR@MHBD@KSDQM@SHUDSNSGDBNLL@MCRmd5sumNQsha1sum QDD3$TRDRmd5@MCsha1 VGHBG@QDMNS@KV@XRHMRS@KKDC #opensslmd5file.tar.gz#Generateanmd5checksumfromfile #opensslsha1file.tar.gz#Generateansha1checksumfromfile #opensslrmd160file.tar.gz#GenerateaRIPEMD-160checksumfromfile 15INSTALLSOFTWARE 5RT@KKXSGDO@BJ@FDL@M@FDQTRDRSGDOQNWXU@QH@AKDENQGSSOESOQDPTDRSR)MA@RGQB GSSOVVVGBBEKDCTONKKNBJ5MHWHMC#LCGSL c)MRS@KK3NESV@QDc 4.5Portsinuse ,HRSDMHMFNODMONQSR #netstat-an|grepLISTEN #lsof-i#LinuxlistallInternetconnections #socklist#Linuxdisplaylistofopensockets #sockstat-4#FreeBSDapplicationlisting #netstat-anp--udp--tcp|grepLISTEN#Linux #netstat-tup#Listactiveconnectionsto/fromsystem(Linux) #netstat-tupl#Listlisteningportsfromsystem(Linux) #netstat-ano#Windows 4.6Firewall #GDBJHE@EHQDV@KKHRQTMMHMFSXOHB@KBNMEHFTQ@SHNMNMKX Linux #iptables-L-n-v#Forstatus Opentheiptablesfirewall #iptables-PINPUTACCEPT#Openeverything #iptables-PFORWARDACCEPT #iptables-POUTPUTACCEPT #iptables-Z#Zerothepacketandbytecountersinallchains #iptables-F#Flushallchains #iptables-X#Deleteallchains FreeBSD #ipfwshow#Forstatus #ipfwlist65535#ifansweris65535denyipfromanytoanythefwisdisabled #sysctlnet.inet.ip.fw.enable=0#Disable #sysctlnet.inet.ip.fw.enable=1#Enable 4.7IPForwardforrouting Linux #GDBJ@MCSGDMDM@AKD)0ENQV@QCVHSG #cat/proc/sys/net/ipv4/ip_forward#CheckIPforward0=off,1=on #echo1/proc/sys/net/ipv4/ip_forward NQDCHSDSBRXRBSKBNMEVHSG net.ipv4.ip_forward=1 FreeBSD #GDBJ@MCDM@AKDVHSG #sysctlnet.inet.ip.forwarding#CheckIPforward0=off,1=on #sysctlnet.inet.ip.forwarding=1 #sysctlnet.inet.ip.fastforwarding=1#Fordedicatedrouterorfirewall Permanentwithentryin/etc/rc.conf: gateway_enable=YES#SettoYESifthishostwillbeagateway. Solaris #ndd-set/dev/ipip_forwarding1#SetIPforward0=off,1=on 4.8NATNetworkAddressTranslation Linux #iptables-tnat-APOSTROUTING-oeth0-jMASQUERADE#toactivateNAT #iptables-tnat-APREROUTING-ptcp-d78.31.70.238--dport20022-jDNAT --to192.168.16.44:22#Portforward20022tointernalIPportssh c.DSVNQJc
  109. 109. #iptables-tnat-APREROUTING-ptcp-d78.31.70.238--dport993:995-jDNAT --to192.168.16.254:993-995#Portforwardofrange993-995 #iprouteflushcache #iptables-L-tnat#CheckNATstatus $DKDSDSGDONQSENQV@QCVHSG $HMRSD@CNE !4GDOQNFQ@LMDSRS@S M@S HRUDQXTRDETKSNSQ@BJ BNMMDBSHNMRHSTRDR/proc/net/ip_conntrackNQ/proc/net/nf_conntrack #netstat-nat-n#showallconnectionswithIPs FreeBSD #natd-s-m-u-dynamic-f/etc/natd.conf-nfxp0 Oredit/etc/rc.confwith: firewall_enable=YES#SettoYEStoenablefirewallfunctionality firewall_type=open#Firewalltype(see/etc/rc.firewall) natd_enable=YES#Enablenatd(iffirewall_enable==YES). natd_interface=tun0#PublicinterfaceorIPaddresstouse. natd_flags=-s-m-u-dynamic-f/etc/natd.conf 0NQSENQV@QCVHSG #cat/etc/natd.conf same_portsyes use_socketsyes unregistered_only #redirect_porttcpinsideIP:2300-23993300-3399#portrange redirect_portudp192.168.51.103:77777777 4.9DNS /M5MHWSGD$.3DMSQHDR@QDU@KHCENQ@KKHMSDQE@BDR@MC@QDRSNQDCHMDSBQDRNKUBNME4GDCNL@HM SNVGHBGSGDGNRSADKNMFRHR@KRNRSNQDCHMSGHREHKD!LHMHL@KBNMEHFTQ@SHNMHR nameserver78.31.70.238 searchsleepyowl.netintern.lab domainsleepyowl.net #GDBJSGDRXRSDLCNL@HMM@LDVHSG #hostname-d#Sameasdnsdomainname Windows /M7HMCNVRSGD$.3@QDBNMEHFTQDCODQHMSDQE@BD4NCHROK@XSGDBNMEHFTQDC$.3@MCSNEKTRGSGD $.3B@BGDTRD #ipconfig/?#Displayhelp #ipconfig/all#SeeallinformationincludingDNS FlushDNS KTRGSGD/3$.3B@BGD
  110. 110. RNLD@OOKHB@SHNMTRHMFSGDHQNVMB@BGDDFHQDENW @MCVHKKAD TM@EEDBSDC #/etc/init.d/nscdrestart#Restartnscdifused-Linux/BSD/Solaris #lookupd-flushcache#OSXTiger #dscacheutil-flushcache#OSXLeopardandnewer #ipconfig/flushdns#Windows Forwardqueries $HFHRXNTEQHDMCSNSDRSSGD$.3RDSSHMFRNQDW@LOKDSGDOTAKHB$.3RDQUDQ213.133.105.2 ns.second-ns.deB@MADTRDCENQSDRSHMF3DDEQNLVGHBGRDQUDQSGDBKHDMSQDBDHUDRSGD@MRVDQ RHLOKHEHDC@MRVDQ #digsleepyowl.net sleepyowl.net.600INA78.31.70.238 ;;SERVER:192.168.51.254#53(192.168.51.254) GSSOSVDDFXMKOQNIDBSRMDSRS@S M@S c.DSVNQJc 14.7screen 3BQDDM@LTRSG@UD G@RSVNL@HMETMBSHNM@KHSHDR a2TMLTKSHOKDSDQLHM@KRDRRHNMVHSGHM@RHMFKDSDQLHM@K a!RS@QSDCOQNFQ@LHRCDBNTOKDCEQNLSGDQD@KSDQLHM@K@MCB@MSGTRQTMHMSGDA@BJFQNTMC 4GDQD@KSDQLHM@KB@MADBKNRDC@MCQD@SS@BGDCK@SDQ Shortstartexample RS@QSRBQDDMVHSG #screen 7HSGHMSGDRBQDDMRDRRHNMVDB@MRS@QS@KNMFK@RSHMFOQNFQ@LKHJDSNO #top .NVCDS@BGVHSGCtrl-aCtrl-d2D@SS@BGSGDSDQLHM@KVHSG #screen-R-D )MCDS@HKSGHRLD@MR)E@RDRRHNMHRQTMMHMF
  111. 111. SGDMQD@SS@BG)EMDBDRR@QXCDS@BG@MCKNFNTSQDLNSDKX EHQRS)EHSV@RMNSQTMMHMFBQD@SDHS@MCMNSHEXSGDTRDQ/Q #screen-x !SS@BGSN@QTMMHMFRBQDDMHM@LTKSHCHROK@XLNCD4GDBNMRNKDHRSGTRRG@QDC@LNMFLTKSHOKD TRDQR6DQXTRDETKENQSD@LVNQJCDATF Screencommands(withinscreen) !KKRBQDDMBNLL@MCRRS@QSVHSGCtrl-a aCtrl-a?GDKO@MCRTLL@QXNEETMBSHNMR aCtrl-acBQD@SD@MMDVVHMCNVSDQLHM@K aCtrl-aCtrl-nandCtrl-aCtrl-pSNRVHSBGSNSGDMDWSNQOQDUHNTRVHMCNVHMSGDKHRS
  112. 112. AX MTLADQ aCtrl-aCtrl-NVGDQD.HR@MTLADQEQNLSN
  113. 113. SNRVHSBGSNSGDBNQQDRONMCHMFVHMCNV aCtrl-aSNFDS@M@UHF@AKDKHRSNEQTMMHMFVHMCNVR aCtrl-aaSNBKD@Q@LHRRDC#SQK @ aCtrl-aCtrl-dSNCHRBNMMDBS@MCKD@UDSGDRDRRHNMQTMMHMFHMSGDA@BJFQNTMC aCtrl-axKNBJSGDRBQDDMSDQLHM@KVHSG@O@RRVNQC aCtrl-a[DMSDQHMSNscrollbackLNCD
  114. 114. DWHSVHSGesc 5RDechodefscrollback5000~/.screenrcSNHMBQD@RDATEEDQCDE@TKSHR dC-u3BQNKKR@G@KEO@FDTO dC-b3BQNKK@ETKKO@FDTO dC-d3BQNKK@G@KEO@FDCNVM dC-f3BQNKK@ETKKO@FDCNVM d/3D@QBGENQV@QC d?3D@QBGA@BJV@QC 4GDRBQDDMRDRRHNMHRSDQLHM@SDCVGDMSGDOQNFQ@LVHSGHMSGDQTMMHMFSDQLHM@KHRBKNRDC@MCXNT KNFNTSEQNLSGDSDQLHM@K 14.8Find 3NLDHLONQS@MSNOSHNMR -xNM3$ -xdevNM,HMTW 3S@XNMSGDR@LDEHKDRXRSDLCDUHMERS@A -execcmd{};%WDBTSDSGDBNLL@MC@MCQDOK@BDZVHSGSGDETKKO@SG -iname,HJD M@LDATSHRB@RDHMRDMRHSHUD -ls$HROK@XHMENQL@SHNM@ANTSSGDEHKDKHJDKR K@ -sizenMHR MJ-'40 -cminnHKDRRS@STRV@RK@RSBG@MFDCMLHMTSDR@FN #find.-typef!-perm-444#Findfilesnotreadablebyall #find.-typed!-perm-111#Finddirsnotaccessiblebyall #find/home/user/-cmin10-print#Filescreatedormodifiedinthelast10min. #find.-name'*.[ch]'|xargsgrep-E'expr'#Search'expr'inthisdirandbelow. c5RDETK#NLL@MCRc
  115. 115. 14.6dd 4GDOQNFQ@LddCHRJCTLONQCDRSQNXCHRJNQRDDSGDLD@MHMFNECC HRTRDCSNBNOXO@QSHSHNMR @MCCHRJR@MCENQNSGDQBNOXSQHBJR4XOHB@KTR@FD #ddif=sourceof=targetbs=bytesizeconv=conversion #kill-INFOPID#Viewddprogress(FreeBSD,OSX) )LONQS@MSBNMUNOSHNMR notruncCNMNSSQTMB@SDSGDNTSOTSEHKD
  116. 116. @KKYDQNRVHKKADVQHSSDM@RYDQNR noerrorBNMSHMTD@ESDQQD@CDQQNQRDFA@CAKNBJR syncO@CDUDQXHMOTSAKNBJVHSG.TKKRSNHAR RHYD 4GDCDE@TKSAXSDRHYDHRNMDAKNBJ 4GD-2
  117. 117. VGDQDSGDO@QSHSHNMS@AKDHRKNB@SDC
  118. 118. HRNMSGD EHQRSAKNBJ
  119. 119. SGDEHQRSAKNBJRNE@CHRJ@QDDLOSX,@QFDQAXSDRHYDR@QDE@RSDQSNBNOXATSQDPTHQD @KRNLNQDLDLNQX Backupandrestore #ddif=/dev/hdaof=/dev/hdcbs=16065b#Copydisktodisk(samesize) #ddif=/dev/sda7of=/home/root.imgbs=4096conv=notrunc,noerror#Backup/ #ddif=/home/root.imgof=/dev/sda7bs=4096conv=notrunc,noerror#Restore/ #ddbs=1Mif=/dev/ad4s3e|gzip-cad4s3e.gz#Zipthebackup #gunzip-dcad4s3e.gz|ddof=/dev/ad0s3ebs=1M#Restorethezip #ddbs=1Mif=/dev/ad4s3e|gzip|ssheedcoba@fry'ddof=ad4s3e.gz'#alsoremote #gunzip-dcad4s3e.gz|ssheedcoba@host'ddof=/dev/ad0s3ebs=1M' #ddif=/dev/ad0of=/dev/ad2skip=1seek=1bs=4kconv=noerror#SkipMBR #Thisisnecessaryifthedestination(ad2)issmaller. #ddif=/vm/FreeBSD-8.2-RELEASE-amd64-memstick.imgof=/dev/disk1bs=10240conv=sync #CopyFreeBSDimagetoUSBmemorystick Recover 4GDBNLL@MCddVHKKQD@CeverysingleblockNESGDO@QSHSHNM)MB@RDNEOQNAKDLRHSHRADSSDQSN TRDSGDNOSHNMconv=sync,noerrorRNCCVHKKRJHOSGDA@CAKNBJ@MCVQHSDYDQNR@SSGDCDRSHM@SHNM !BBNQCHMFKXHSHRHLONQS@MSSNRDSSGDAKNBJRHYDDPT@KNQRL@KKDQSG@MSGDCHRJAKNBJRHYD!JRHYD RDDLRR@ED
  120. 120. RDSHSVHSGbs=1k)E@CHRJG@RA@CRDBSNQR@MCSGDC@S@RGNTKCADQDBNUDQDCEQNL @O@QSHSHNM
  121. 121. BQD@SD@MHL@FDEHKDVHSGCC
  122. 122. LNTMSSGDHL@FD@MCBNOXSGDBNMSDMSSN@MDVCHRJ 7HSGSGDNOSHNMnoerror
  123. 123. CCVHKKRJHOSGDA@CRDBSNQR@MCVQHSDYDQNRHMRSD@C
  124. 124. SGTRNMKXSGDC@S@ BNMS@HMDCHMSGDA@CRDBSNQRVHKKADKNRS #ddif=/dev/hdaof=/dev/nullbs=1m#Checkforbadblocks #ddbs=1kif=/dev/hda1conv=sync,noerror,notrunc|gzip|ssh#Sendtoremote root@fry'ddof=hda1.gzbs=1k' #ddbs=1kif=/dev/hda1conv=sync,noerror,notruncof=hda1.img#Storeintoanimage #mount-oloop/hda1.img/mnt#Mounttheimage(page13) #rsync-ax/mnt//newdisk/#Copyonanewdisk #ddif=/dev/hdaof=/dev/hda#Refreshthemagneticstate #Theaboveisusefultorefreshadisk.Itisperfectlysafe,butmustbeunmounted. Delete #ddif=/dev/zeroof=/dev/hdc#Deletefulldisk #ddif=/dev/urandomof=/dev/hdc#Deletefulldiskbetter #kill-USR1PID#Viewddprogress(Linux) #kill-INFOPID#Viewddprogress(FreeBSD) MBRtricks 4GD-2BNMS@HMRSGDANNSKN@CDQ@MCSGDO@QSHSHNMS@AKD@MCHRAXSDRRL@KK4GDEHQRS@QD ENQSGDANNSKN@CDQ
  125. 125. SGDAXSDRSN@QDENQSGDO@QSHSHNMS@AKD #ddif=/dev/sdaof=/mbr_sda.bakbs=512count=1#BackupthefullMBR #ddif=/dev/zeroof=/dev/sdabs=512count=1#DeleteMBRandpartitiontable #ddif=/mbr_sda.bakof=/dev/sdabs=512count=1#RestorethefullMBR #ddif=/mbr_sda.bakof=/dev/sdabs=446count=1#Restoreonlythebootloader #ddif=/mbr_sda.bakof=/dev/sdabs=1count=64skip=446seek=446#Restorepartitiontable c5RDETK#NLL@MCRc 4GDQNTSDQ@MRVDQDC@MCSGDQDRONMRDHRSGD!DMSQX!MXDMSQXB@MADPTDQHDC @MCSGD$.3RDQUDQB@MADRDKDBSDCVHSG #digMXgoogle.com #dig@127.0.0.1NSsun.com#Totestthelocalserver #dig@204.97.212.10NSMXheise.de#Queryanexternalserver #digAXFR@ns1.xname.orgcb.vu#Getthefullzone(zonetransfer) 4GDOQNFQ@LGNRSHR@KRNONVDQETK #host-tMXcb.vu#GetthemailMXentry #host-tNS-Tsun.com#GettheNSrecordoveraTCPconnection #host-asleepyowl.net#Geteverything Reversequeries HMCSGDM@LDADKNMFHMFSN@M)0@CCQDRRHM @CCQ@QO@ 4GHRB@MADCNMDVHSGdig
  126. 126. host@MC nslookup #dig-x78.31.70.238 #host78.31.70.238 #nslookup78.31.70.238 /etc/hosts 3HMFKDGNRSRB@MADBNMEHFTQDCHMSGDEHKDDSBGNRSRHMRSD@CNEQTMMHMFnamedKNB@KKXSNQDRNKUDSGD GNRSM@LDPTDQHDR4GDENQL@SHRRHLOKD
  127. 127. ENQDW@LOKD 78.31.70.238sleepyowl.netsleepyowl 4GDOQHNQHSXADSVDDMGNRSR@MC@CMRPTDQX
  128. 128. SG@SHRSGDM@LDQDRNKTSHNMNQCDQ
  129. 129. B@MADBNMEHFTQDCHM /etc/nsswitch.conf!.$DSBGNRSBNME4GDEHKD@KRNDWHRSRNM7HMCNVR
  130. 130. HSHRTRT@KKXHM C:WINDOWSSYSTEM32DRIVERSETC 4.10DHCP Linux 3NLDCHRSQHATSHNMR3T3% TRDCGBOBC@RBKHDMS4GDCDE@TKSHMSDQE@BDHRDSG #dhcpcd-neth0#Triggerarenew(doesnotalwayswork) #dhcpcd-keth0#releaseandshutdown 4GDKD@RDVHSGSGDETKKHMENQL@SHNMHRRSNQDCHM /var/lib/dhcpcd/dhcpcd-eth0.info FreeBSD QDD3$@MC$DAH@M TRDRCGBKHDMS4NBNMEHFTQD@MHMSDQE@BDENQDW@LOKDAFD QTM #dhclientbge0 4GDKD@RDVHSGSGDETKKHMENQL@SHNMHRRSNQDCHM /var/db/dhclient.leases.bge0 5RD /etc/dhclient.conf SNOQDODMCNOSHNMRNQENQBDCHEEDQDMSNOSHNMR #cat/etc/dhclient.conf interfacerl0{ prependdomain-name-servers127.0.0.1; defaultdomain-namesleepyowl.net; supersededomain-namesleepyowl.net; } Windows 4GDCGBOKD@RDB@MADQDMDVDCVHSGipconfig c.DSVNQJc
  131. 131. #ipconfig/renew#renewalladapters #ipconfig/renewLAN#renewtheadapternamedLAN #ipconfig/releaseWLAN#releasetheadapternamedWLAN 9DRHSHR@FNNCHCD@SNQDM@LDXNT@C@OSDQVHSGRHLOKDM@LDR 4.11Trafficanalysis LNM HR@RL@KKBNMRNKDA@MCVHCSGLNMHSNQ@MCB@MCHROK@XSGDEKNVNMCHEEDQDMSHMSDQE@BDR Sniffwithtcpdump #tcpdump-nl-ibge0notportsshandsrc(192.168.16.121or192.168.16.54) #tcpdump-n-ieth1net192.168.16.121#selectto/fromasingleIP #tcpdump-n-ieth1net192.168.16.0/24#selecttrafficto/fromanetwork #tcpdump-ldumptail-fdump#Bufferedoutput #tcpdump-irl0-wtraffic.rl0#Writetrafficheadersinbinaryfile #tcpdump-irl0-s0-wtraffic.rl0#Writetraffic+payloadinbinaryfile #tcpdump-rtraffic.rl0#Readfromfile(alsoforethereal #tcpdumpport80#Thetwoclassiccommands #tcpdumphostgoogle.com #tcpdump-ieth0-Xport(110or143)#Checkifpoporimapissecure #tcpdump-n-ieth0icmp#Onlycatchpings #tcpdump-ieth0-s0-Aport80|grepGET#-s0forfullpacket-AforASCII !CCHSHNM@KHLONQS@MSNOSHNMR -A0QHMSD@BGO@BJDSRHMBKD@QSDWSVHSGNTSGD@CDQ -X0QHMSO@BJDSRHMGDW@MC!3#)) -l-@JDRSCNTSKHMDATEEDQDC -D0QHMS@KKHMSDQE@BDR@U@HK@AKD /M7HMCNVRTRDVHMCTLOEQNLVVVVHMOB@ONQF5RDVHMCTLO $SNKHRSSGDHMSDQE@BDR Scanwithnmap .L@O HR@ONQSRB@MMDQVHSG/3CDSDBSHNM
  132. 132. HSHRTRT@KKXHMRS@KKDCNMLNRSCHRSQHATSHNMR@MCHR@KRN @U@HK@AKDENQ7HMCNVR)EXNTCNMSRB@MXNTQRDQUDQR
  133. 133. G@BJDQRCNHSENQXNT #nmapcb.vu#scansallreservedTCPportsonthehost #nmap-sP192.168.16.0/24#FindoutwhichIPareusedandbywhichhoston0/24 #nmap-sS-sV-Ocb.vu#DoastealthSYNscanwithversionandOSdetection PORTSTATESERVICEVERSION 22/tcpopensshOpenSSH3.8.1p1FreeBSD-20060930(protocol2.0) 25/tcpopensmtpSendmailsmtpd8.13.6/8.13.6 80/tcpopenhttpApachehttpd2.0.59((FreeBSD)DAV/2PHP/4. [...] Running:FreeBSD5.X Uptime33.120days(sinceFriAug3111:41:042007) /SGDQMNMRS@MC@QCATSTRDETKSNNKR@QDhpingVVVGOHMFNQF @M)0O@BJDS@RRDLAKDQ@M@KXYDQ @MCfpingEOHMFRNTQBDENQFDMDS EOHMFB@MBGDBJLTKSHOKDGNRSRHM@QNTMC QNAHME@RGHNM 4.12Trafficcontrol(QoS) 4Q@EEHBBNMSQNKL@M@FDRSGDPTDTHMF
  134. 134. ONKHBHMF
  135. 135. RBGDCTKHMF
  136. 136. @MCNSGDQSQ@EEHBO@Q@LDSDQRENQ@ MDSVNQJ4GDENKKNVHMFDW@LOKDR@QDRHLOKDOQ@BSHB@KTRDRNESGD,HMTW@MCQDD3$B@O@AHKHSHDRSN ADSSDQTRDSGD@U@HK@AKDA@MCVHCSG Limitupload $3,NQB@AKDLNCDLRG@UD@KNMFPTDTDSNHLOQNUDSGDTOKN@CSGQNTFGOTS(NVDUDQEHKKHMFSGD PTDTDVHSG@E@RSCDUHBDDFDSGDQMDS VHKKCQ@L@SHB@KKXCDBQD@RDSGDHMSDQ@BSHUHSX)SHRSGDQDENQD TRDETKSNKHLHSSGDCDUHBDTOKN@CQ@SDSNL@SBGSGDOGXRHB@KB@O@BHSXNESGDLNCDL
  137. 137. SGHRRGNTKC FQD@SKXHLOQNUDSGDHMSDQ@BSHUHSX3DSSN@ANTSNESGDLNCDLL@WHL@KB@AKD RODDC GSSOODNOKDRTTFBG]SFQALNM GSSOHMRDBTQDNQFML@O c.DSVNQJc 14.3mail 4GDmailBNLL@MCHR@A@RHB@OOKHB@SHNMSNQD@C@MCRDMCDL@HK
  138. 138. HSHRTRT@KKXHMRS@KKDC4NRDMC @MDL@HKRHLOKXSXODL@HKTRDQCNL@HM4GDEHQRSKHMDHRSGDRTAIDBS
  139. 139. SGDMSGDL@HKBNMSDMS 4DQLHM@SD@MCRDMCSGDDL@HKVHSG@RHMFKDCNS HM@MDVKHMD%W@LOKD #mailc@cb.vu Subject:Yourtextisfulloftypos Foramoment,nothinghappened.Then,afterasecondorso, nothingcontinuedtohappen. . EOT # 4GHRHR@KRNVNQJHMFVHSG@OHOD #echoThisisthemailbody|mailc@cb.vu 4GHRHR@KRN@RHLOKDV@XSNSDRSSGDL@HKRDQUDQ 14.4tar 4GDBNLL@MCtarS@OD@QBGHUD BQD@SDR@MCDWSQ@BSR@QBGHUDRNEEHKD@MCCHQDBSNQHDR4GD@QBGHUD S@QHRTMBNLOQDRRDC
  140. 140. @BNLOQDRRDC@QBGHUDG@RSGDDWSDMRHNMSFYNQS@QFYYHO NQSAYAYHO $NMNSTRD@ARNKTSDO@SGVGDMBQD@SHMF@M@QBGHUD
  141. 141. XNTOQNA@AKXV@MSSNTMO@BJHSRNLDVGDQD DKRD3NLDSXOHB@KBNLL@MCR@QD Create #cd/ #tar-cfhome.tarhome/#archivethewhole/homedirectory(cforcreate) #tar-czfhome.tgzhome/#samewithzipcompression #tar-cjfhome.tbzhome/#samewithbzip2compression /MKXHMBKTCDNMDNQSVN CHQDBSNQHDREQNL@SQDD
  142. 142. ATSJDDOSGDQDK@SHUDRSQTBSTQDNQDW@LOKD @QBGHUDTRQKNB@KDSB@MCTRQKNB@KVVV@MCSGDEHQRSCHQDBSNQXHMSGD@QBGHUDRGNTKCADKNB@K #tar-C/usr-czflocal.tgzlocal/etclocal/www #tar-C/usr-xzflocal.tgz#Tountarthelocaldirinto/usr #cd/usr;tar-xzflocal.tgz#Isthesameasabove Extract #tar-tzfhome.tgz#lookinsidethearchivewithoutextracting(list) #tar-xfhome.tar#extractthearchivehere(xforextract) #tar-xzfhome.tgz#samewithzipcompression(-xjfforbzip2compression) #removeleadingpathgallery2andextractintogallery #tar--strip-components1-zxvfgallery2.tgz-Cgallery/ #tar-xjfhome.tbzhome/colin/file.txt#Restoreasinglefile #tar-xOfhome.tbzhome/colin/file.txt#Printfiletostdout(noextraction) Moreadvanced #tarcdir/|gzip|sshuser@remote'ddof=dir.tgz'#archdir/andstoreremotely. #tarcvf-`find.-print`backup.tar#archthecurrentdirectory. #tar-cf--C/etc.|tarxpf--C/backup/etc#Copydirectories #tar-cf--C/etc.|sshuser@remotetarxpf--C/backup/etc#Remotecopy. #tar-czfhome.tgz--exclude'*.o'--exclude'tmp/'home/ 14.5zip/unzip :HOEHKDRB@MADD@RHDQSNRG@QDVHSG7HMCNVR #zip-rfileName.zip/path/to/dir#zipdirintofilefileName.zip #unzipfileName.zip#uncompresszipfile #unzip-lfileName.zip#listfilesinsidearchive #unzip-cfileName.zipfileinside.txt#printonefiletostdout(noextraction) #unzipfileName.zipfileinside.txt#extractonefileonly c5RDETK#NLL@MCRc
  143. 143. #svnmovefoo.cbar.c#Move(rename)files #svndeletesome_old_file#Deletefiles 14USEFULCOMMANDS KDRRO [UHO [L@HKO [S@QO [YHOO [CCO [RBQDDMO [EHMCO [ -HRBDKK@MDNTRO 14.1less 4GDlessBNLL@MCCHROK@XR@SDWSCNBTLDMSNMSGDBNMRNKD)SHROQDRDMSNMLNRSHMRS@KK@SHNM #lessunixtoolbox.xhtml 3NLDHLONQS@MSBNLL@MCR@QD.RS@MCRENQ;BNMSQNK= ;.= hHFNNCGDKONMCHROK@X f^F^VSPACENQV@QCNMDVHMCNVNQ.KHMDR b^BESC-v@BJV@QCNMDVHMCNVNQ.KHMDR FNQV@QCENQDUDQKHJDS@HK E /pattern3D@QBGENQV@QCENQ. SG L@SBGHMFKHMD ?pattern3D@QBGA@BJV@QCENQ. SG L@SBGHMFKHMD n2DOD@SOQDUHNTRRD@QBGENQ. SGNBBTQQDMBD N2DOD@SOQDUHNTRRD@QBGHMQDUDQRDCHQDBSHNM qPTHS 14.2vi 6HHROQDRDMSNM!.9,HMTW5MHWHMRS@KK@SHNMMNSFDMSNN @MCHSHRSGDQDENQDTRDETKSNJMNVRNLD A@RHBBNLL@MCR4GDQD@QDSVNLNCDRBNLL@MCLNCD@MCHMRDQSHNMLNCD4GDBNLL@MCRLNCD HR@BBDRRDCVHSG[ESC]
  144. 144. SGDHMRDQSHNMLNCDVHSGi5RD:helpHEXNT@QDKNRS 4GDDCHSNQRnano@MCpico@QDTRT@KKX@U@HK@AKDSNN@MC@QDD@RHDQ)-(/ SNTRD Quit :wMDVEHKDM@LDR@UDSGDEHKDSNMDVEHKDM@LD :wqor:xR@UD@MCPTHS :q!PTHSVHSGNTSR@UHMF Searchandmove /string3D@QBGENQV@QCENQRSQHMF ?string3D@QBGA@BJENQRSQHMF n3D@QBGENQMDWSHMRS@MBDNERSQHMF N3D@QBGENQOQDUHNTRHMRS@MBDNERSQHMF {-NUD@O@Q@FQ@OGA@BJ }-NUD@O@Q@FQ@OGENQV@QC 1G-NUDSNSGDEHQRSKHMDNESGDEHKD nG-NUDSNSGDMSGKHMDNESGDEHKD G-NUDSNSGDK@RSKHMDNESGDEHKD :%s/OLD/NEW/g3D@QBG@MCQDOK@BDDUDQXNBBTQQDMBD Deletecopypastetext dd(dw)#TSBTQQDMSKHMDVNQC D#TSSNSGDDMCNESGDKHMD x$DKDSDBTS BG@Q@BSDQ yy(yw)#NOXKHMDVNQC @ESDQBTQRNQ P0@RSD@ESDQBTQRNQ u5MCNK@RSLNCHEHB@SHNM U5MCN@KKBG@MFDRSNBTQQDMSKHMD c5RDETK#NLL@MCRc Linux NQ@+AHSTOKN@CLNCDL #tcqdiscadddeveth0roottbfrate480kbitlatency50msburst1540 #tc-sqdisclsdeveth0#Status #tcqdiscdeldeveth0root#Deletethequeue #tcqdiscchangedeveth0roottbfrate220kbitlatency50msburst1540 FreeBSD QDD3$TRDRSGDdummynetSQ@EEHBRG@ODQVGHBGHRBNMEHFTQDCVHSGHOEV0HODR@QDTRDCSNRDSKHLHSR SGDA@MCVHCSGHMTMHSRNE;+[-=ZAHSR[XSDR
  145. 145. LD@MRTMKHLHSDCA@MCVHCSG5RHMFSGDR@LDOHOD MTLADQVHKKQDBNMEHFTQDHSNQDW@LOKDKHLHSSGDTOKN@CA@MCVHCSGSN+AHS #kldloaddummynet#loadthemoduleifnecessary #ipfwpipe1configbw500Kbit/s#createapipewithlimitedbandwidth #ipfwaddpipe1ipfrommetoany#divertthefulluploadintothepipe Qualityofservice Linux 0QHNQHSXPTDTHMFVHSGtcSNNOSHLHYD6N)03DDSGDETKKDW@LOKDNMUNHO HMENNQFNQ VVVGNVSNENQFDBNL3TOONRD6N)0TRDRTCONMONQSR@MCCDUHBDDSGBNTKC@KRN ADOOONQRN 4GDENKKNVHMFBNLL@MCRCDEHMDSGD1N3SNSGQDDPTDTDR@MCENQBDSGD6N)0SQ@EEHB SNPTDTDVHSG1N30x1e@KKAHSRRDS 4GDCDE@TKSSQ@EEHBEKNVRHMSNPTDTD@MC1N3Minimize- DelayEKNVRHMSNPTDTD #tcqdiscadddeveth0roothandle1:priopriomap2222222211111110 #tcqdiscadddeveth0parent1:1handle10:sfq #tcqdiscadddeveth0parent1:2handle20:sfq #tcqdiscadddeveth0parent1:3handle30:sfq #tcfilteradddeveth0protocolipparent1:prio1u32 matchipdport100000x3C00flowid1:1#useserverportrange matchipdst123.23.0.1flowid1:1#or/anduseserverIP 3S@STR@MCQDLNUDVHSG #tc-sqdisclsdeveth0#queuestatus #tcqdiscdeldeveth0root#deleteallQoS Calculateportrangeandmask 4GDSBEHKSDQCDEHMDRSGDONQSQ@MFDVHSGONQS@MCL@RJVGHBGXNTG@UDSNB@KBTK@SDHMCSGD. endingNESGDONQSQ@MFD
  146. 146. CDCTBDSGDQ@MFD@MCBNMUDQSSN(%84GHRHRXNTQL@RJ%W@LOKDENQ
  147. 147. SGDQ@MFDHR #2^13(8192)100002^14(16384)#endingis2^14=16384 #echoobase=16;(2^14)-1024|bc#maskis0x3C00 FreeBSD 4GDL@WKHMJA@MCVHCSGHR+AHSR@MCVDCDEHMDPTDTDRVHSGOQHNQHSXENQ6N)0RRG@KK SGDQDRS #ipfwpipe1configbw500Kbit/s #ipfwqueue1configpipe1weight100 #ipfwqueue2configpipe1weight10 #ipfwqueue3configpipe1weight1 #ipfwadd10queue1protoudpdst-port10000-11024 #ipfwadd11queue1protoudpdst-ip123.23.0.1#or/anduseserverIP #ipfwadd20queue2dsp-portssh #ipfwadd30queue3frommetoany#alltherest 3S@STR@MCQDLNUDVHSG #ipfwlist#rulesstatus #ipfwpipelist#pipestatus #ipfwflush#deletesallrulesbutdefault c.DSVNQJc
  148. 148. 4.13NISDebugging 3NLDBNLL@MCRVGHBGRGNTKCVNQJNM@VDKKBNMEHFTQDC.)3BKHDMS #ypwhich#gettheconnectedNISservername #domainname#TheNISdomainnameasconfigured #ypcatgroup#shoulddisplaythegroupfromtheNISserver #cd/var/ypmake#Rebuildtheypdatabase #rpcinfo-pservername#ReportRPCservicesoftheserver )RXOAHMCQTMMHMF #psauxww|grepypbind /usr/sbin/ypbind-s-m-Sservername1,servername2#FreeBSD /usr/sbin/ypbind#Linux #yppollpasswd.byname Mappasswd.bynamehasordernumber1190635041.MonSep2413:57:212007 Themasterserverisservername.domain.net. Linux #cat/etc/yp.conf ypserverservername domaindomain.netbroadcast 4.14Netcat .DSB@S MB HRADSSDQJMNVM@RSGDMDSVNQJ3VHRR!QLX+MHED
  149. 149. HSB@ML@MHOTK@SD
  150. 150. BQD@SDNQ QD@CVQHSD4#0)0BNMMDBSHNMR(DQDRNLDTRDETKDW@LOKDR
  151. 151. SGDQD@QDL@MXLNQDNMSGDMDS
  152. 152. ENQ DW@LOKDF KN@CDCDT;= @MCGDQD 9NTLHFGSMDDCSNTRDSGDBNLL@MCnetcatHMRSD@CNEnc!KRNRDDSGDRHLHK@QBNLL@MCRNB@S Filetransfer #NOX@K@QFDENKCDQNUDQ@Q@VSBOBNMMDBSHNM4GDSQ@MREDQHRUDQXPTHBJMNOQNSNBNKNUDQGD@C @MCXNTCNMSMDDCSNLDRRTOVHSG.3NQ3-NQ40NQRN
  153. 153. RHLOKXL@JDSGDEHKD@U@HK@AKDNMSGD RDQUDQ
  154. 154. @MCFDSHSEQNLSGDBKHDMS(DQDHRSGDRDQUDQ)0@CCQDRR server#tar-cf--CVIDEO_TS.|nc-l-p4444#Servetarfolderonport4444 client#nc192.168.1.14444|tarxpf--CVIDEO_TS#Pullthefileonport4444 server#catlargefile|nc-l5678#Serverasinglefile client#nc192.168.1.15678largefile#Pullthesinglefile server#ddif=/dev/da0|nc-l4444#Serverpartitionimage client#nc192.168.1.14444|ddof=/dev/da0#Pullpartitiontoclone client#nc192.168.1.14444|ddof=da0.img#Pullpartitiontofile Otherhacks 3ODBH@KKXGDQD
  155. 155. XNTLTRSJMNVVG@SXNT@QDCNHMF Remoteshell /OSHNM DNMKXNMSGD7HMCNVRUDQRHNM/QTRDMB #nc-lp4444-e/bin/bash#Providearemoteshell(serverbackdoor) #nc-lp4444-ecmd.exe#remoteshellforWindows Emergencywebserver 3DQUD@RHMFKDEHKDNMONQSHM@KNNO #whiletrue;donc-l-p80unixtoolbox.xhtml;done Chat !KHBD@MCNAB@MBG@SNUDQ@RHLOKD4#0RNBJDS4GDSDWSHRSQ@MREDQQDCVHSGSGDDMSDQJDX alice#nc-lp4444 bob#nc192.168.1.14444 GSSOMDSB@SRNTQBDENQFDMDS GSSOVVVF KN@CDCDTMDSB@S @ BNTOKD NE TRDETK DW@LOKDR GSSOVVVSDQLHM@KKX HMBNGDQDMSBNLAKNFEDV TRDETK MDSB@S SQHBJR c.DSVNQJc #groupaddsubversion #groupmod-Auser1subversion #chown-Rroot:subversion/home/svn #chmod-R770/home/svn Remoteaccesswithhttp(apache) 2DLNSD@BBDRRNUDQGSSOGSSOR HRSGDNMKXFNNCRNKTSHNMENQ@K@QFDQTRDQFQNTO4GHRLDSGNCTRDR SGD@O@BGD@TSGDMSHB@SHNM
  156. 156. MNSSGDKNB@K@BBNTMSR4GHRHR@SXOHB@KATSRL@KK@O@BGDBNMEHFTQ@SHNM LoadModuledav_modulemodules/mod_dav.so LoadModuledav_svn_modulemodules/mod_dav_svn.so LoadModuleauthz_svn_modulemodules/mod_authz_svn.so#Onlyforaccesscontrol Location/svn DAVsvn #any/svn/fooURLwillmaptoarepository/home/svn/foo SVNParentPath/home/svn AuthTypeBasic AuthNameSubversionrepository AuthzSVNAccessFile/etc/apache2/svn.acl AuthUserFile/etc/apache2/svn-passwd Requirevalid-user /Location 4GD@O@BGDRDQUDQMDDCRETKK@BBDRRSNSGDQDONRHSNQX #chown-Rwww:www/home/svn #QD@SD@TRDQVHSGGSO@RRVC #htpasswd-c/etc/svn-passwduser1#-ccreatesthefile Accesscontrolsvn.aclexample #Defaultitreadaccess.*=wouldbedefaultnoaccess [/] *=r [groups] project1-developers=joe,jack,jane #Givewriteaccesstothedevelopers [project1:] @project1-developers=rw 13.2SVNcommandsandusage 3DD@KRNSGD3TAUDQRHNM1THBJ2DEDQDMBD#@QC 4NQSNHRD36. HR@MHBD7HMCNVRHMSDQE@BD Import !MDVOQNIDBS
  157. 157. SG@SHR@CHQDBSNQXVHSGRNLDEHKDR
  158. 158. HRHLONQSDCHMSNSGDQDONRHSNQXVHSGSGDimport BNLL@MC)LONQSHR@KRNTRDCSN@CC@CHQDBSNQXVHSGHSRBNMSDMSSN@MDWHRSHMFOQNIDBS #svnhelpimport#Gethelpforanycommand #Addanewdirectory(withcontent)intothesrcdironproject1 #svnimport/project1/newdirhttp://host.url/svn/project1/trunk/src-m'addnewdir' TypicalSVNcommands #svncohttp://host.url/svn/project1/trunk#Checkoutthemostrecentversion #Tagsandbranchesarecreatedbycopying #svnmkdirhttp://host.url/svn/project1/tags/#Createthetagsdirectory #svncopy-mTagrc1rel.http://host.url/svn/project1/trunk http://host.url/svn/project1/tags/1.0rc1 #svnstatus[--verbose]#Checkfilesstatusintoworkingdir #svnaddsrc/file.hsrc/file.cpp#Addtwofiles #svncommit-m'Addednewclassfile'#Committhechangeswithamessage #svnlshttp://host.url/svn/project1/tags/#Listalltags GSSOVVVBROTSONYM@MOKBRNA@MHDB0@ODQRRUM QDEB@QCOCE GSSOSNQSNHRDRUMSHFQHRNQF c36.c
  159. 159. #cvsupdate-A#Resetanystickytag(ordate,option) #cvsaddnewfile#Addanewfile #cvsadd-kbnewfile#Addanewbinaryfile #cvscommitfile1file2#Committhetwofilesonly #cvscommit-mmessage#Commitallchangesdonewithamessage Createapatch )SHRADRSSNBQD@SD@MC@OOKX@O@SBGEQNLSGDVNQJHMFCDUDKNOLDMSCHQDBSNQXQDK@SDCSNSGDOQNIDBS
  160. 160. NQEQNLVHSGHMSGDRNTQBDCHQDBSNQX #cd/devel/project #diff-Naurolddirnewdirpatchfile#Createapatchfromadirectoryorafile #diff-Nauroldfilenewfilepatchfile Applyapatch 3NLDSHLDRHSHRMDBDRR@QXSNRSQHO@CHQDBSNQXKDUDKEQNLSGDO@SBG
  161. 161. CDODMCHMFGNVHSV@RBQD@SDC )MB@RDNECHEEHBTKSHDR
  162. 162. RHLOKXKNNJ@SSGDEHQRSKHMDRNESGDO@SBG@MCSQX O
  163. 163. ONQ O #cd/devel/project #patch--dry-run-p0patchfile#Testthepathwithoutapplyingit #patch-p0patchfile #patch-p1patchfile#stripoffthe1stlevelfromthepath 13SVN 3DQUDQRDSTOO [36.33(O [36.NUDQGSSOO [36.TR@FDO 3TAUDQRHNM36. HR@UDQRHNMBNMSQNKRXRSDLCDRHFMDCSNADSGDRTBBDRRNQNE#63#NMBTQQDMS 6DQRHNMR3XRSDL 4GDBNMBDOSHRRHLHK@QSN#63
  164. 164. ATSL@MXRGNQSBNLHMFRVGDQDHLOQNUDC3DD@KRN SGD36.ANNJ 13.1Serversetup 4GDHMHSH@SHNMNESGDQDONRHSNQXHRE@HQKXRHLOKDGDQDENQDW@LOKD/home/svn/LTRSDWHRS #svnadmincreate--fs-typefsfs/home/svn/project1 .NVSGD@BBDRRSNSGDQDONRHSNQXHRL@CDONRRHAKDVHSG afile://$HQDBSEHKDRXRSDL@BBDRRVHSGSGDRUMBKHDMSVHSG4GHRQDPTHQDRKNB@KODQLHRRHNMR NMSGDEHKDRXRSDL asvn://NQsvn+ssh://2DLNSD@BBDRRVHSGSGDRUMRDQUDRDQUDQ@KRNNUDQ33( 4GHR QDPTHQDRKNB@KODQLHRRHNMRNMSGDEHKDRXRSDLCDE@TKSONQSSBO ahttp://2DLNSD@BBDRRVHSGVDAC@UTRHMF@O@BGD.NKNB@KTRDQR@QDMDBDRR@QXENQSGHR LDSGNC 5RHMFSGDKNB@KEHKDRXRSDL
  165. 165. HSHRMNVONRRHAKDSNHLONQS@MCSGDMBGDBJNTS@MDWHRSHMFOQNIDBS 5MKHJDVHSG#63HSHRMNSMDBDRR@QXSNBCHMSNSGDOQNIDBSCHQDBSNQX
  166. 166. RHLOKXFHUDSGDETKKO@SG #svnimport/project1/file:///home/svn/project1/trunk-m'Initialimport' #svncheckoutfile:///home/svn/project1 4GDMDVCHQDBSNQXSQTMJHRNMKX@BNMUDMSHNM
  167. 167. SGHRHRMNSQDPTHQDC Remoteaccesswithssh .NRODBH@KRDSTOHRQDPTHQDCSN@BBDRRSGDQDONRHSNQXUH@RRG
  168. 168. RHLOKXQDOK@BDfile://VHSGsvn+ssh/ hostnameNQDW@LOKD #svncheckoutsvn+ssh://hostname/home/svn/project1 !RVHSGSGDKNB@KEHKD@BBDRR
  169. 169. DUDQXTRDQMDDCR@MRRG@BBDRRSNSGDRDQUDQVHSG@KNB@K@BBNTMS @MC@KRNQD@CVQHSD@BBDRR4GHRLDSGNCLHFGSADRTHS@AKDENQ@RL@KKFQNTO!KKTRDQRBNTKCADKNMF SN@RTAUDQRHNMFQNTOVGHBGNVMRSGDQDONRHSNQX
  170. 170. ENQDW@LOKD GSSORTAUDQRHNMSHFQHRNQF GSSORUMANNJQDC AD@MBNLDM c36.c 5SSHSCP 0TAKHBJDXO [HMFDQOQHMSO [3#0O [4TMMDKHMFO 3DDNSGDQSQHBJRRRGBLC 5.1Publickeyauthentication #NMMDBSSN@GNRSVHSGNTSO@RRVNQCTRHMFOTAKHBJDX@TSGDMSHB@SHNM4GDHCD@HRSN@OODMCXNTQ OTAKHBJDXSNSGD@TSGNQHYDC?JDXREHKDNMSGDQDLNSDGNRSNQSGHRDW@LOKDKDSRconnecthost- clienttohost-server
  171. 171. SGDJDXHRFDMDQ@SDCNMSGDBKHDMS7HSGBXFVHMXNTLHFGSG@UDSNBQD@SD XNTQGNLDCHQDBSNX@MCSGDRRGCHQDBSNQXVHSG#mkdir-p/home/USER/.ssh a5RDRRG JDXFDMSNFDMDQ@SD@JDXO@HQ~/.ssh/id_dsaHRSGDOQHU@SDJDX
  172. 172. ~/.ssh/ id_dsa.pubHRSGDOTAKHBJDX a#NOXNMKXSGDOTAKHBJDXSNSGDRDQUDQ@MC@OODMCHSSNSGDEHKD~/.ssh/authorized_keys2 NMXNTQGNLDNMSGDRDQUDQ #ssh-keygen-tdsa-N'' #cat~/.ssh/id_dsa.pub|sshyou@host-servercat-~/.ssh/authorized_keys2 UsingtheWindowsclientfromssh.com 4GDMNMBNLLDQBH@KUDQRHNMNESGDRRGBNLBKHDMSB@MADCNVMKN@CDCSGDL@HMESORHSD ESORRGBNLOTARRG+DXRFDMDQ@SDCAXSGDRRGBNLBKHDMSMDDCSNADBNMUDQSDCENQSGD/ODM33( RDQUDQ4GHRB@MADCNMDVHSGSGDRRG JDXFDMBNLL@MC a#QD@SD@JDXO@HQVHSGSGDRRGBNLBKHDMS3DSSHMFR 5RDQ!TSGDMSHB@SHNM 'DMDQ@SD.DV a)TRD+DXSXOD$3!JDXKDMFSG a#NOXSGDOTAKHBJDXFDMDQ@SDCAXSGDRRGBNLBKHDMSSNSGDRDQUDQHMSNSGD]RRGENKCDQ a4GDJDXR@QDHM#$NBTLDMSR@MC3DSSHMFR53%2.!-%!OOKHB@SHNM $@S@33(5RDQ+DXR a5RDSGDRRG JDXFDMBNLL@MCNMSGDRDQUDQSNBNMUDQSSGDJDX #cd~/.ssh #ssh-keygen-i-fkeyfilename.pubauthorized_keys2 Notice:7DTRDC@$3!JDX
  173. 173. 23!HR@KRNONRRHAKD4GDJDXHRMNSOQNSDBSDCAX@O@RRVNQC UsingputtyforWindows 0TSSX HR@RHLOKD@MCEQDDRRGBKHDMSENQ7HMCNVR a#QD@SD@JDXO@HQVHSGSGDOT449FDMOQNFQ@L a3@UDSGDOTAKHB@MCOQHU@SDJDXRENQDW@LOKDHMSN#$NBTLDMSR@MC 3DSSHMFR53%2.!-%RRG a#NOXSGDOTAKHBJDXSNSGDRDQUDQHMSNSGD]RRGENKCDQ #scp.ssh/puttykey.pubroot@192.168.51.254:.ssh/ a5RDSGDRRG JDXFDMBNLL@MCNMSGDRDQUDQSNBNMUDQSSGDJDXENQ/ODM33( #cd~/.ssh #ssh-keygen-i-fputtykey.pubauthorized_keys2 a0NHMSSGDOQHU@SDJDXKNB@SHNMHMSGDOTSSXRDSSHMFR#NMMDBSHNM 33( !TSG 5.2Checkfingerprint !SSGDEHQRSKNFHM
  174. 174. RRGVHKK@RJHESGDTMJMNVMGNRSVHSGSGDEHMFDQOQHMSG@RSNADRSNQDCHMSGDJMNVM GNRSR4N@UNHC@L@M HM SGD LHCCKD@SS@BJSGD@CLHMHRSQ@SNQNESGDRDQUDQB@MRDMCXNTSGDRDQUDQ EHMFDQOQHMSVGHBGHRSGDMBNLO@QDCNMSGDEHQRSKNFHM5RDssh-keygen-lSNFDSSGDEHMFDQOQHMSNM SGDRDQUDQ #ssh-keygen-l-f/etc/ssh/ssh_host_rsa_key.pub#ForRSAkey 204861:33:be:9b:ae:6c:36:31:fd:83:98:b7:99:2d:9f:cd/etc/ssh/ssh_host_rsa_key.pub GSSOAKNFTQEHWBNL RRG BNLL@MCR SQHBJR GSSOVVVBGH@QJFQDDMDMCNQFTJ]RFS@SG@LOTSSXCNVMKN@CGSLK c33(3#0c
  175. 175. #ssh-keygen-l-f/etc/ssh/ssh_host_dsa_key.pub#ForDSAkey(default) 204814:4a:aa:d9:73:25:46:6d:0a:48:35:c7:f4:16:d4:ee/etc/ssh/ssh_host_dsa_key.pub .NVSGDBKHDMSBNMMDBSHMFSNSGHRRDQUDQB@MUDQHEXSG@SGDHRBNMMDBSHMFSNSGDQHFGSRDQUDQ #sshlinda Theauthenticityofhost'linda(192.168.16.54)'can'tbeestablished. DSAkeyfingerprintis14:4a:aa:d9:73:25:46:6d:0a:48:35:c7:f4:16:d4:ee. Areyousureyouwanttocontinueconnecting(yes/no)?yes 5.3Securefiletransfer 3NLDRHLOKDBNLL@MCR #scpfile.txthost-two:/tmp #scpjoe@host-two:/www/*.html/www/tmp #scp-rjoe@host-two:/www/www/tmp )M+NMPTDQNQNQ-HCMHFGS#NLL@MCDQHSHRONRRHAKDSN@BBDRR@QDLNSDEHKDRXRSDLVHSGSGD@CCQDRR fish://user@gate(NVDUDQSGDHLOKDLDMS@SHNMHRUDQXRKNV TQSGDQLNQDHSHRONRRHAKDSNLNTMS@QDLNSDENKCDQVHSGsshfs@EHKDRXRSDLBKHDMSA@RDCNM3#0 3DDETRDRRGER ssh_exchange_identification:Connectionclosedbyremotehost 7HSGSGHRDQQNQSQXSGDENKKNVHMFNMSGDRDQUDQ echo'SSHD:ALL'/etc/hosts.allow /etc/init.d/sshdrestart 5.4Tunneling 33(STMMDKHMF@KKNVRSNENQV@QCNQQDUDQRDENQV@QC@ONQSNUDQSGD33(BNMMDBSHNM
  176. 176. SGTRRDBTQHMF SGDSQ@EEHB@MC@BBDRRHMFONQSRVGHBGVNTKCNSGDQVHRDADAKNBJDC4GHRNMKXVNQJRVHSG4#04GD FDMDQ@KMNLDMBK@STQDENQENQV@QC@MCQDUDQRDHRRDD@KRNRRG@MC.!4DW@LOKD #ssh-Llocalport:desthost:destportuser@gate#desthostasseenfromthegate #ssh-Rdestport:desthost:localportuser@gate#forwardsyourlocalporttodestination #desthost:localportasseenfromtheclientinitiatingthetunnel #ssh-Xuser@gate#ToforceXforwarding 4GHRVHKKBNMMDBSSNF@SD@MCENQV@QCSGDKNB@KONQSSNSGDGNRSCDRSGNRSCDRSONQS.NSDCDRSGNRS HRSGDCDRSHM@SHNMGNRSasseenbythegate
  177. 177. RNHESGDBNMMDBSHNMHRSNSGDF@SD
  178. 178. SGDMCDRSGNRSHR KNB@KGNRS-NQDSG@MNMDONQSENQV@QCHRONRRHAKD Directforwardonthegate ,DSR@XVDV@MSSN@BBDRRSGD#63ONQS @MCGSSOONQS VGHBG@QDQTMMHMFNMSGDF@SD 4GHRHRSGDRHLOKDRSDW@LOKD
  179. 179. CDRSGNRSHRSGTRKNB@KGNRS
  180. 180. @MCVDTRDSGDONQSKNB@KKXHMRSD@CNE RNVDCNMSMDDCSNADQNNS/MBDSGDRRGRDRRHNMHRNODM
  181. 181. ANSGRDQUHBDR@QD@BBDRRHAKDNMSGD KNB@KONQSR #ssh-L2401:localhost:2401-L8080:localhost:80user@gate Netbiosandremotedesktopforwardtoasecondserver ,DSR@X@7HMCNVRRLARDQUDQHRADGHMCSGDF@SD@MCHRMNSQTMMHMFRRG7DMDDC@BBDRRSNSGD RLARG@QD@MC@KRNQDLNSDCDRJSNOSNSGDRDQUDQ #ssh-L139:smbserver:139-L3388:smbserver:3389user@gate 4GDRLARG@QDB@MMNVAD@BBDRRDCVHSG
  182. 182. ATSNMKXHESGDKNB@KRG@QDHRCHR@AKDC
  183. 183. ADB@TRDthelocalshareislisteningonport139 )SHRONRRHAKDSNJDDOSGDKNB@KRG@QDDM@AKDC

×