1,編輯以下文件
vim /etc/csf/csf.allow
2,通過ip138.com之類的查詢本地IP的網(wǎng)站獲得當(dāng)前局域網(wǎng)所在的IP地址,然后加入到這個(gè)配置文件里邊,保存退出;
3,重啟CSF防火墻:
csf -r
搞定收工!
]]>]]>
mysqldump --opt -u username -p dbname | gzip > dbnamesql.sql.gz
回車后會(huì)要求輸入密碼,不出意外,一會(huì)功夫就導(dǎo)出成功了。
]]>
du -b –max-depth 1 | sort -nr | perl -pe ‘s{([0-9]+)}{sprintf”%.1f%s”, $1>=2**30? ($1/2**30, “G”): $1>=2**20? ($1/2**20, “M”):$1>=2**10? ($1/2**10, “K”): ($1, “”)}e’
]]>find / -type f -size +100000k -ls
]]>netstat -ltnp | grep ‘:88’
tcp 0 0 :::88 :::* LISTEN 3697/httpd
由上邊可以看出占用88端口的是3697/httpd,因此執(zhí)行以下命令殺死這個(gè)進(jìn)程,然后再次重啟apache就可以了:
]]># kill -9 3697
# service httpd restart
假設(shè)之前為了某些權(quán)限問題,直接給予了所有文件跟文件夾777的權(quán)限,現(xiàn)在想恢復(fù)到之前文件夾是755,文件是644的權(quán)限,可以通過以下命令行來(lái)實(shí)現(xiàn):
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
第一個(gè)命令是查找所有的文件夾并強(qiáng)制給予755的權(quán)限,第二個(gè)命令是查找所有的文件并強(qiáng)制給予644的權(quán)限。
]]>yes | cp -a new/files/* files
]]>Find all the files whose name is tecmint.txt in a current working directory.
# find . -name tecmint.txt
./tecmint.txt
2. Find Files Under Home Directory
Find all the files under /home directory with name tecmint.txt.
# find /home -name tecmint.txt
/home/tecmint.txt
3. Find Files Using Name and Ignoring Case
Find all the files whose name is tecmint.txt and contains both capital and small letters in /home directory.
# find /home -iname tecmint.txt
./tecmint.txt
./Tecmint.txt
4. Find Directories Using Name
Find all directories whose name is Tecmint in / directory.
# find / -type d -name Tecmint
/Tecmint
5. Find PHP Files Using Name
Find all php files whose name is tecmint.php in a current working directory.
# find . -type f -name tecmint.php
./tecmint.php
6. Find all PHP Files in Directory
Find all php files in a directory.
# find . -type f -name “*.php”
./tecmint.php
./login.php
./index.php
Part II – Find Files Based on their Permissions
7. Find Files With 777 Permissions
Find all the files whose permissions are 777.
# find . -type f -perm 0777 -print
8. Find Files Without 777 Permissions
Find all the files without permission 777.
# find / -type f ! -perm 777
9. Find SGID Files with 644 Permissions
Find all the SGID bit files whose permissions set to 644.
# find / -perm 2644
10. Find Sticky Bit Files with 551 Permissions
Find all the Sticky Bit set files whose permission are 551.
# find / -perm 1551
11. Find SUID Files
Find all SUID set files.
# find / -perm /u=s
12. Find SGID Files
Find all SGID set files.
# find / -perm /g+s
13. Find Read Only Files
Find all Read Only files.
# find / -perm /u=r
14. Find Executable Files
Find all Executable files.
# find / -perm /a=x
15. Find Files with 777 Permissions and Chmod to 644
Find all 777 permission files and use chmod command to set permissions to 644.
# find / -type f -perm 0777 -print -exec chmod 644 {} \;
16. Find Directories with 777 Permissions and Chmod to 755
Find all 777 permission directories and use chmod command to set permissions to 755.
# find / -type d -perm 777 -print -exec chmod 755 {} \;
17. Find and remove single File
To find a single file called tecmint.txt and remove it.
# find . -type f -name “tecmint.txt” -exec rm -f {} \;
18. Find and remove Multiple File
To find and remove multiple files such as .mp3 or .txt, then use.
# find . -type f -name “*.txt” -exec rm -f {} \;
OR
# find . -type f -name “*.mp3” -exec rm -f {} \;
19. Find all Empty Files
To file all empty files under certain path.
# find /tmp -type f -empty
20. Find all Empty Directories
To file all empty directories under certain path.
# find /tmp -type d -empty
21. File all Hidden Files
To find all hidden files, use below command.
# find /tmp -type f -name “.*”
Part III – Search Files Based On Owners and Groups
22. Find Single File Based on User
To find all or single file called tecmint.txt under / root directory of owner root.
# find / -user root -name tecmint.txt
23. Find all Files Based on User
To find all files that belongs to user Tecmint under /home directory.
# find /home -user tecmint
24. Find all Files Based on Group
To find all files that belongs to group Developer under /home directory.
# find /home -group developer
25. Find Particular Files of User
To find all .txt files of user Tecmint under /home directory.
# find /home -user tecmint -iname “*.txt”
Part IV – Find Files and Directories Based on Date and Time
26. Find Last 50 Days Modified Files
To find all the files which are modified 50 days back.
# find / -mtime 50
27. Find Last 50 Days Accessed Files
To find all the files which are accessed 50 days back.
# find / -atime 50
28. Find Last 50-100 Days Modified Files
To find all the files which are modified more than 50 days back and less than 100 days.
# find / -mtime +50 –mtime -100
29. Find Changed Files in Last 1 Hour
To find all the files which are changed in last 1 hour.
# find / -cmin -60
30. Find Modified Files in Last 1 Hour
To find all the files which are modified in last 1 hour.
# find / -mmin -60
31. Find Accessed Files in Last 1 Hour
To find all the files which are accessed in last 1 hour.
# find / -amin -60
Part V – Find Files and Directories Based on Size
32. Find 50MB Files
To find all 50MB files, use.
# find / -size 50M
33. Find Size between 50MB – 100MB
To find all the files which are greater than 50MB and less than 100MB.
# find / -size +50M -size -100M
34. Find and Delete 100MB Files
To find all 100MB files and delete them using one single command.
# find / -size +100M -exec rm -rf {} \;
35. Find Specific Files and Delete
Find all .mp3 files with more than 10MB and delete them using one single command.
# find / -type f -name *.mp3 -size +10M -exec rm {} \;
That’s it, We are ending this post here, In our next article we will
discuss more about other Linux commands in depth with practical
examples. Let us know your opinions on this article using our comment
section.
好了閑話少說,言歸正傳,馬上開始這個(gè)方案。
1)第一步要解決的一個(gè)問題就是如何實(shí)現(xiàn)服務(wù)器遠(yuǎn)程SCP的時(shí)候,無(wú)需輸入密碼,假設(shè)我們想從A服務(wù)器自動(dòng)遠(yuǎn)程SCP到B服務(wù)器(B服務(wù)器為bluehost主機(jī)開啟了SSH服務(wù)),那么首先在A服務(wù)器上需要生成一個(gè)Public_key:
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa
Enter passphrase (empty for no passphrase):直接回車
Enter same passphrase again:直接回車
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
f6:61:a8:27:35:cf:4c:6d:13:22:70:cf:4c:c8:a0:23 root@host1
這樣,在/root/.ssh/路徑下會(huì)生成id_rsa,和id_rsa.pub,其中id_rsa是密鑰,id_rsa.pub是公鑰。
2)把在A機(jī)生成的id_rsa.pub拷貝到B機(jī)上,假設(shè)拷貝到B機(jī)的臨時(shí)目錄下,如:
scp /root/.ssh/id_rsa.pub root@B機(jī)IP:/tmp
3)這里分兩種情況,當(dāng)B服務(wù)器也是獨(dú)立服務(wù)器的時(shí)候,用root帳號(hào)登陸B(tài)機(jī),進(jìn)入其主目錄,創(chuàng)建authorized_keys文件,并設(shè)置好權(quán)限。
cd ~/.ssh
cat /tmp/id_rsa.pub >>authorized_keys
chmod 400 authorized_keys
rm -f /tmp/id_rsa.pub
而當(dāng)B服務(wù)器是bluehost這種主機(jī)的時(shí)候,我們是沒有root賬號(hào)可用的,自然也是無(wú)法進(jìn)入~/.ssh目錄去生成authorized_keys的,幸好bluehost提供了基于cPanel上的方案如下:
至此已成功的對(duì)A服務(wù)器進(jìn)行了無(wú)密碼SSH登陸B(tài)主機(jī)的授權(quán)。
4)測(cè)試
在A機(jī)上轉(zhuǎn)到root帳號(hào),嘗試登錄B機(jī)。看看是不是不要密碼.
說明:
authorized_keys文件的權(quán)限很重要,如果設(shè)置為777,那么登錄的時(shí)候,還是需要提供密碼的。
vim /www/backup/remote_backup.sh ? 加入如下內(nèi)容:
#!/bin/bash
cd /******/mysql
scp -r * [email protected]:*******/database/
cd /******/web
scp -r * [email protected]:*******/web/
chmod 750 remote_backup.sh
然后將此腳本加入計(jì)劃任務(wù):
crontab -e
00 1 * * 7 ? /bin/bash /www/backup/remote_backup.sh
每周第七天一點(diǎn)鐘自動(dòng)執(zhí)行此腳本。
service crond restart
搞定。
]]>