今天一早(21071116)就接到user反應點陣式印表機無法列印.....還不只單一個案,有些是整個辦公室都有相同的問題,作業系統涵括windows 7與windows 10......檢查許久還是找不到問題!便開始懷疑是否是更新造成?一檢查,windows7與windows 10今天各有兩支更新被安裝!嘗試著先移除一支試試!Bingo!!抓到兇手了.....
在windows7下的KB4048957與windows10下的KB4048954,KB4048955(兩隻都會造成異常,有看到就移除!)這兩支更新程式一移除,一切都正常了......😤
移除程式,重新開機後,記得到windows update內去把這支更新隱藏,不然會再自動重新安裝......😔
2017年11月16日 星期四
2017年9月25日 星期一
Ubuntu ext4 Quota設定
安裝
sudo apt-get install quota
修改磁區
修改 /etc/fstab 檔案,在啟用限額的分割區加上 usrquota 及 grpquota 選項,例如
/dev/sdb1 /DATA ext4 defaults,usrquota,grpquota 0 1
修改完後需要重新掛載修改的磁區
sudo mount -o remount /DATA
設定quota
使用 quotacheck初始化quota檔案:quota藉由檔案紀錄使用者或群組的使用情況,首先得 檢查配額的檔案系統及建立磁碟用量表格
sudo quotacheck -cmug /DATA
-c 建立quota檔案
-m 不重新掛載磁區,唯讀
-u 檢查使用者檔案
-g 檢查群組檔案
指令會在/DATA下建立 aquota.user 及 aquota.group 兩個檔案
啟動quota
sudo quotaon -av
-a, --all turn quotas on for all filesystems
-v, --verbose print more messages
編輯使用者磁碟限額規則
sudo edquota -u UserNmae
Disk quotas for user u1 (uid 1001):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 100000 102400 0 0 0
第一欄 Filesystem:啟用的分割區
第二欄 blocks:使用者已經使用的區塊
第三欄 soft: 非強制性磁碟空間限制,單位:KB
第四欄 hard:強制性磁碟空間限制,單位:KB
第五欄 inodes:使用者已使用的檔案數
第六欄 soft:非強制性的 inode 限制
第七欄 hard:強制性的 inode 限制
編輯群組磁碟限額規則
sudo edquota -g GroupName
Disk quotas for group u1 (gid 1001):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 0 0 0 0 0
常用指令
套用某使用者的規則
sudo edquota -p 被參考者 套用者1, 套用者2 ..
確認使用者配額
sudo quota UserName
確認群組配額
sudo quota -g GroupName
檢視單一目錄磁碟配額報告
sudo repquota /home
檢視所有配額中的磁碟用量報告
sudo repquota -aug
sudo apt-get install quota
修改磁區
修改 /etc/fstab 檔案,在啟用限額的分割區加上 usrquota 及 grpquota 選項,例如
/dev/sdb1 /DATA ext4 defaults,usrquota,grpquota 0 1
修改完後需要重新掛載修改的磁區
sudo mount -o remount /DATA
設定quota
使用 quotacheck初始化quota檔案:quota藉由檔案紀錄使用者或群組的使用情況,首先得 檢查配額的檔案系統及建立磁碟用量表格
sudo quotacheck -cmug /DATA
-c 建立quota檔案
-m 不重新掛載磁區,唯讀
-u 檢查使用者檔案
-g 檢查群組檔案
指令會在/DATA下建立 aquota.user 及 aquota.group 兩個檔案
啟動quota
sudo quotaon -av
-a, --all turn quotas on for all filesystems
-v, --verbose print more messages
編輯使用者磁碟限額規則
sudo edquota -u UserNmae
Disk quotas for user u1 (uid 1001):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 100000 102400 0 0 0
第一欄 Filesystem:啟用的分割區
第二欄 blocks:使用者已經使用的區塊
第三欄 soft: 非強制性磁碟空間限制,單位:KB
第四欄 hard:強制性磁碟空間限制,單位:KB
第五欄 inodes:使用者已使用的檔案數
第六欄 soft:非強制性的 inode 限制
第七欄 hard:強制性的 inode 限制
編輯群組磁碟限額規則
sudo edquota -g GroupName
Disk quotas for group u1 (gid 1001):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 0 0 0 0 0
常用指令
套用某使用者的規則
sudo edquota -p 被參考者 套用者1, 套用者2 ..
確認使用者配額
sudo quota UserName
確認群組配額
sudo quota -g GroupName
檢視單一目錄磁碟配額報告
sudo repquota /home
檢視所有配額中的磁碟用量報告
sudo repquota -aug
2017年9月7日 星期四
Postfix 3.6.4 安裝
Postfix 安裝
sudo apt-get install postfix
SMTP AUTH (使用Dovecot)
Dovecot安裝
sudo apt-get install dovecot-core
編輯檔案/etc/dovecot/conf.d/10-master,設定Dovecot接受client端提出的授權認證要求。找到「service auth {」這個段落,修改如下設定:
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
存檔後須重新啟動dovecot。
設定投遞程式
要將郵件存入~/Maildir,需明確指定『投遞程式』,由Postfix指定投遞程式將郵件存入指定目錄。
1.使用Postfix內建提供的local程式,這個方式只要在main.cf內設定好
home_mailbox = Maildir/
即可運作
2.使用procmail,除了需在main.cf內設定
home_mailbox = Maildir/
mailbox_command = procmail -a "$EXTENSION"
還需在/etc/procmailrc檔案內加入以下內容:
SHELL="/bin/bash"
SENDMAIL="/usr/sbin/sendmail -oi -t"
LOGFILE="/var/log/procmail.log"
DEFAULT="$HOME/Maildir/"
MAILDIR="$HOME/Maildir/"
:0
* ^X-Spam-Status: Yes
.spam/
另外,若系統尚未安裝procmail得再安裝
sudo apt-get install procmail
設定postscreen
編輯/etc/postfix/main.cf:
postscreen_access_list = permit_mynetworks,
cidr:/etc/postfix/postscreen_access.cidr
sudo apt-get install postfix
SMTP AUTH (使用Dovecot)
Dovecot安裝
sudo apt-get install dovecot-core
編輯檔案/etc/dovecot/conf.d/10-master,設定Dovecot接受client端提出的授權認證要求。找到「service auth {」這個段落,修改如下設定:
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
再編輯/etc/dovecot/conf.d/10-auth.conf,設定SMTP Client端與SASL Server連線時協商的機制。
auth_mechanisms = plain login
Dovecot預設禁用明碼驗證,disable_plaintext_auth = yes;但若有開啟TLS加密則不在限制內!所以得在Postfix內再加上TLS的連線設定!
設定Postfix SMTP AUTH
#SMTP AUTH
#告知Postfix使用的SASL類型是dovecot
smtpd_sasl_type = dovecot
#SASL認證的相對路徑,是在/var/spool/postfix下
smtpd_sasl_path = private/auth
#啟用SMTP AUTH
smtpd_sasl_auth_enable = yes
#在信件表頭「Received:」留下SASL登入帳號。可省略
smtpd_sasl_authenticated_header = yes
#不可使用暱名授權
smtpd_sasl_security_options = noanonymous
安裝dovecot-pop3d dovecot-imapd
sudo apt-get install dovecot-pop3d dovecot-imapd
設定Dovecot的TLS
編輯/etc/dovecot/conf.d/10-ssl.conf
ssl = yes
ssl_cert = </etc/dovecot/private/dovecot.pem
ssl_key = </etc/dovecot/private/dovecot.key
sudo apt-get install dovecot-pop3d dovecot-imapd
設定Postfix使用TLS加密
編輯/etc/postfix/main.cf,新增以下內容:
編輯/etc/postfix/main.cf,新增以下內容:
## TLS parameters
#default: empty;none:TLS will not be used;may:Opportunistic TLS;encrypt:Mandatory TLS encryption
#2.3以後版本使用,取代2.2以前的smtpd_use_tls=yes
#user client smtp to server
smtpd_tls_security_level = encrypt
#mail server smtp to mail server
smtp_tls_security_level = encrypt
#記錄遠端伺服器是否支援STARTTLS
smtp_tls_note_starttls_offer = yes
#default: empty;Name of the file containing the optional Postfix SMTP server TLS session cache.
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
#default: empty;Name of the file containing the optional Postfix SMTP client TLS session cache.
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
#憑證位置
#postfix <= 3.3
#自訂 letsencrypt
#smtpd_tls_cert_file = /etc/path/cert.pem
#smtpd_tls_key_file = /etc/path/privkey.pem
#smtp_tls_CApath = /etc/path/
#postfix >= 3.4
#letsencrypt
smtpd_tls_chain_files = /etc/path/privkey.pem,
/etc/path/fullchain.pem
#在mail的header加上SSL/TLS 相關資
smtpd_tls_received_header = yes
#客戶端/客戶發送郵件到我的服務器時,是否強制加密
smtpd_tls_auth_only = yes
#Log
smtpd_tls_loglevel = 1
設定Dovecot的TLS
編輯/etc/dovecot/conf.d/10-ssl.conf
ssl = yes
ssl_cert = </etc/dovecot/private/dovecot.pem
ssl_key = </etc/dovecot/private/dovecot.key
#要求 客户端 在连接时提供 有效的 SSL 证书,并进行身份验证
ssl_verify_client_cert = yes
#上述設定為yes時的搭配設定
ssl_ca = /etc/path/fullchain.pem
此時需注意系統是否已經自動產生
ssl_cert = </etc/dovecot/private/dovecot.pem
ssl_key = </etc/dovecot/private/dovecot.key
若無,需至/usr/share/dovecot下先編輯dovecot-openssl.cnf檔案內容,如果不想做其他變更,只需修改[ req_distinguished_name ]項目下的設定值:
[ req_distinguished_name ]
organizationName = Dovecot mail server
organizationalUnitName = @commonName@<-----單位名稱
commonName = @commonName@ #<-----此處需改成自己主機的名稱
emailAddress = @emailAddress@
countryName = TW
檔案內容設定可以參閱:
http://dovecot.org/doc/dovecot-openssl.cnf
http://www-01.ibm.com/support/knowledgecenter/SSB23S_1.1.0.12/com.ibm.ztpf-ztpfdf.doc_put.12/gtps7/cfgcert.html
編輯完成後再用管理員權限執行/usr/share/dovecot/mkcert.sh,即可產生需要的兩個檔案。
dovecot預設使用mbox格式,若有設定postfix使用maildir格式,須修改/etc/dovecot/conf.d/10-mail.conf,將信箱位置與格式改為:
#mail_location = maildir:~/Maildir
# Minimum SSL protocol version to use. Potentially recognized values are SSLv3,
# TLSv1, TLSv1.1, TLSv1.2 and TLSv1.3, depending on the OpenSSL version used.
#
# Dovecot also recognizes values ANY and LATEST. ANY matches with any protocol
# version, and LATEST matches with the latest version supported by library.
ssl_min_protocol = TLSv1.2
此時需注意系統是否已經自動產生
ssl_cert = </etc/dovecot/private/dovecot.pem
ssl_key = </etc/dovecot/private/dovecot.key
若無,需至/usr/share/dovecot下先編輯dovecot-openssl.cnf檔案內容,如果不想做其他變更,只需修改[ req_distinguished_name ]項目下的設定值:
[ req_distinguished_name ]
organizationName = Dovecot mail server
organizationalUnitName = @commonName@<-----單位名稱
commonName = @commonName@ #<-----此處需改成自己主機的名稱
emailAddress = @emailAddress@
countryName = TW
檔案內容設定可以參閱:
http://dovecot.org/doc/dovecot-openssl.cnf
http://www-01.ibm.com/support/knowledgecenter/SSB23S_1.1.0.12/com.ibm.ztpf-ztpfdf.doc_put.12/gtps7/cfgcert.html
編輯完成後再用管理員權限執行/usr/share/dovecot/mkcert.sh,即可產生需要的兩個檔案。
dovecot預設使用mbox格式,若有設定postfix使用maildir格式,須修改/etc/dovecot/conf.d/10-mail.conf,將信箱位置與格式改為:
#mail_location = maildir:~/Maildir
#指定Maildir用UTF-8編碼
mail_location = maildir:~/Maildir:UTF-8
存檔後須重新啟動dovecot。
設定dovecot開機啟動
sudo systemctl enable dovecot
啟動dovecot
sudo systemctl start dovecot
設定投遞程式
要將郵件存入~/Maildir,需明確指定『投遞程式』,由Postfix指定投遞程式將郵件存入指定目錄。
1.使用Postfix內建提供的local程式,這個方式只要在main.cf內設定好
home_mailbox = Maildir/
即可運作
2.使用procmail,除了需在main.cf內設定
home_mailbox = Maildir/
mailbox_command = procmail -a "$EXTENSION"
還需在/etc/procmailrc檔案內加入以下內容:
SHELL="/bin/bash"
SENDMAIL="/usr/sbin/sendmail -oi -t"
LOGFILE="/var/log/procmail.log"
DEFAULT="$HOME/Maildir/"
MAILDIR="$HOME/Maildir/"
:0
* ^X-Spam-Status: Yes
.spam/
另外,若系統尚未安裝procmail得再安裝
sudo apt-get install procmail
設定postscreen
編輯/etc/postfix/main.cf:
postscreen_access_list = permit_mynetworks,
cidr:/etc/postfix/postscreen_access.cidr
postscreen_access_list是設定黑白名單檔案,預設值permit_mynetworks,是指mynetworks所設定的網段不必測試,直接略過postscreen。
postscreen_access.cidr檔案內容如下:
192.168.1.1 permit
192.168.0.0/24 reject
postscreen_access.cidr檔案內容採循環評估方式,先符合者就先執行,上述規則為192.168.1.1傳回permit給postscreen,表示允許略過postscreen,而192.168.0.0/24則直接拒絕連線!
編輯/etc/postfix/master.cf,註解下列這行:
#smtp inet n - - - - smtpd
並開啟下列幾行
smtp inet n - - - 1 postscreen
smtpd pass - - - - - smtpd
dnsblog unix - - - - 0 dnsblog
tlsproxy unix - - - - 0 tlsproxy
submission inet n - - - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt #(may)
-o smtpd_sasl_auth_enable=yes
-o smtpd_reject_unlisted_recipient=no
postscreen_access.cidr檔案內容如下:
192.168.1.1 permit
192.168.0.0/24 reject
postscreen_access.cidr檔案內容採循環評估方式,先符合者就先執行,上述規則為192.168.1.1傳回permit給postscreen,表示允許略過postscreen,而192.168.0.0/24則直接拒絕連線!
編輯/etc/postfix/master.cf,註解下列這行:
#smtp inet n - - - - smtpd
並開啟下列幾行
smtp inet n - - - 1 postscreen
smtpd pass - - - - - smtpd
dnsblog unix - - - - 0 dnsblog
tlsproxy unix - - - - 0 tlsproxy
submission inet n - - - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt #(may)
-o smtpd_sasl_auth_enable=yes
-o smtpd_reject_unlisted_recipient=no
另外在/etc/postfix/main.cf也可加入以下兩行,啟用垃圾郵件黑名單的機制:
#阻擋mial的分數門檻
postscreen_dnsbl_threshold = 2
# dnsbl_sites*權重分數
postscreen_dnsbl_sites = zen.spamhaus.org*2
bl.spamcop.net*1 b.barracudacentral.org*1
以上述為例,阻擋的分數門檻是2,在zen.spamhaus.org發現時佔2分,在bl.spamcop.net、 b.barracudacentral.org發現時各佔1分,所以在zen.spamhaus.org發現時立即阻擋信件,但須在bl.spamcop.net、 b.barracudacentral.org同時發現,才達到阻擋郵件的2分門檻!
另外再加入以下三行,設定postscreen測試失敗時,如何回應client:
#寄件者被列在黑名單內(postscreen_access.cidr)的回應
postscreen_blacklist_action = drop
#postscreen_greet_wait (default: normal: 6s, overload: 2s),寄件者在等候時間內再次連線時的動作
postscreen_greet_action = drop
#寄件者被列在DNSBL名單內時的動作
postscreen_dnsbl_action = drop
上述三行的預設值為ignore,只會記錄和收集統計資料,不會真的拒絕連線!若設為enforce,則會回應550的拒絕訊息,並在記錄檔內留下helo/寄件者/收件者的資訊;drop則回應代碼521,並立即中斷連線!下次客戶端連接時重複此測試。
#阻擋mial的分數門檻
postscreen_dnsbl_threshold = 2
# dnsbl_sites*權重分數
postscreen_dnsbl_sites = zen.spamhaus.org*2
bl.spamcop.net*1 b.barracudacentral.org*1
以上述為例,阻擋的分數門檻是2,在zen.spamhaus.org發現時佔2分,在bl.spamcop.net、 b.barracudacentral.org發現時各佔1分,所以在zen.spamhaus.org發現時立即阻擋信件,但須在bl.spamcop.net、 b.barracudacentral.org同時發現,才達到阻擋郵件的2分門檻!
另外再加入以下三行,設定postscreen測試失敗時,如何回應client:
#寄件者被列在黑名單內(postscreen_access.cidr)的回應
postscreen_blacklist_action = drop
#postscreen_greet_wait (default: normal: 6s, overload: 2s),寄件者在等候時間內再次連線時的動作
postscreen_greet_action = drop
#寄件者被列在DNSBL名單內時的動作
postscreen_dnsbl_action = drop
上述三行的預設值為ignore,只會記錄和收集統計資料,不會真的拒絕連線!若設為enforce,則會回應550的拒絕訊息,並在記錄檔內留下helo/寄件者/收件者的資訊;drop則回應代碼521,並立即中斷連線!下次客戶端連接時重複此測試。
郵件記錄檔分析
安裝pflogsumm與mailutils套件(會用到mail指令)
sudo apt-get update
sudo apt-get update
sudo apt-get install pflogsumm mailutils
建立一個script,例如/etc/postfix/gen-pflog.sh,內容如下:
#!/bin/bash
#管理員郵件位址或本機帳號名稱
mailto=it@demo.tw
#產生報表,寄給管理員
/usr/sbin/pflogsumm -u 5 -h 5 --problems_first \
-d today /var/log/mail.log \
| mail -s "pflogsumm report $(date)" $mailto
存檔後給予執行的權限
接著用crontab排程,在指定時間執行:
59 23 * * * /etc/postfix/gen-pflog.sh &> /dev/null
建立一個script,例如/etc/postfix/gen-pflog.sh,內容如下:
#!/bin/bash
#管理員郵件位址或本機帳號名稱
mailto=it@demo.tw
#產生報表,寄給管理員
/usr/sbin/pflogsumm -u 5 -h 5 --problems_first \
-d today /var/log/mail.log \
| mail -s "pflogsumm report $(date)" $mailto
存檔後給予執行的權限
接著用crontab排程,在指定時間執行:
59 23 * * * /etc/postfix/gen-pflog.sh &> /dev/null
2017年8月12日 星期六
Nginx隱藏伺服器版本與名稱
安裝nginx-extras
sudo apt-get install nginx-extras
編輯 /etc/nginx/nginx.conf,在http段落 新增以下兩行:
more_set_headers "Server: Your_New_Server_Name";
server_tokens off;
第一行,自訂伺服器名稱,第二行隱藏伺服器版本。
存檔後重新啟動nginx!
若要隱藏透過php查詢到伺服器與版本,需修改/etc/nginx/fastcgi.conf,針對下面這行
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
可以拿掉$nginx_version,或者直接註解掉這一行!
sudo apt-get install nginx-extras
編輯 /etc/nginx/nginx.conf,在http段落 新增以下兩行:
more_set_headers "Server: Your_New_Server_Name";
server_tokens off;
第一行,自訂伺服器名稱,第二行隱藏伺服器版本。
存檔後重新啟動nginx!
若要隱藏透過php查詢到伺服器與版本,需修改/etc/nginx/fastcgi.conf,針對下面這行
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
可以拿掉$nginx_version,或者直接註解掉這一行!
2017年8月7日 星期一
Ubuntu 16.04 Nginx proxy 設定
在/etc/nginx/sites-available下新增一個設定檔,比如proxy,編輯內容如下:
server
{
resolver 8.8.4.4 valid=30s;
resolver_timeout 600s;
listen 8888;
location /
{
proxy_pass http://$http_host$request_uri;
}
}
說明如下:
resolver 8.8.4.4 valid=30s; 指定使用的dns主機ip,指定傳送封包的有效存活時間
resolver_timeout 60s; 指定dns名稱解析逾時時間
listen 8888; proxy使用的連接埠
proxy_pass http://$http_host$request_uri; proxy主機使用的通訊協定及主機位址,$http_host和$request_uri是nginx內建的變數,可以自動取得主機和uri值
設定完後存擋,接著到/etc/nginx/sites-enabled下將剛剛的設定檔做連結到這個路徑下,並重新啟動nginx
$sudo ln -s proxy
$sudo service nginx restart
設定完成!
接著再client端瀏覽器上設定proxy主機位址即可!Nginx proxy不支援https的代理!!
server
{
resolver 8.8.4.4 valid=30s;
resolver_timeout 600s;
listen 8888;
location /
{
proxy_pass http://$http_host$request_uri;
}
}
說明如下:
resolver 8.8.4.4 valid=30s; 指定使用的dns主機ip,指定傳送封包的有效存活時間
resolver_timeout 60s; 指定dns名稱解析逾時時間
listen 8888; proxy使用的連接埠
proxy_pass http://$http_host$request_uri; proxy主機使用的通訊協定及主機位址,$http_host和$request_uri是nginx內建的變數,可以自動取得主機和uri值
設定完後存擋,接著到/etc/nginx/sites-enabled下將剛剛的設定檔做連結到這個路徑下,並重新啟動nginx
$sudo ln -s proxy
$sudo service nginx restart
設定完成!
接著再client端瀏覽器上設定proxy主機位址即可!Nginx proxy不支援https的代理!!
2017年7月26日 星期三
TCP Wrappers 簡易設定
適用範圍:
1.由 super daemon (xinetd) 所管理的服務
2.僅適用 TCP daemon(有少數例外的狀況)
3.有支援libwrap.so模組的服務,可以用ldd指令來確認
ldd 判斷某個可執行的 binary 檔案含有什麼動態函式庫
-v :列出所有內容資訊;
-d :重新將資料有遺失的 link 點秀出來!
-r :將 ELF 有關的錯誤內容秀出來!
使用ldd查詢運行的服務是否有包含libwrap 函式庫,有包含的服務才能使用TCP Wrappers做控管,以下以sshd與postfix來做查詢:
$ ldd /usr/sbin/sshd |grep libwrap
libwrap.so.0 => /lib/x86_64-linux-gnu/libwrap.so.0 (0x00007f46028e5000)
sshd有查詢到使用libwrap 函式庫!
$ldd /usr/sbin/postfix |grep libwrap/etc/hosts.allow
postfix沒有查詢到使用libwrap 函式庫
因此TCP Wrappers只可以控管sshd,而無法控管postfix!
TCP Wrappers透過/etc/hosts.allow與/etc/hosts.deny兩個檔案來管理服務,順序如下:
1.先比對/etc/hosts.allow,若符合檔案內的設定規則就放行
2.若/etc/hosts.allow比對完後沒有符合的規則設定,再比對/etc/hosts.deny,若符合規則就阻擋
3.若依序比對完兩個檔案後都沒有符合的規則,最後還是放行!
/etc/hosts.allow與/etc/hosts.deny的檔案格式
<服務 (程式名稱)> : <來源IP 或領域 或主機名稱> : 允許 (allow) 或拒絕 (deny)
內容分成三個小區段來看,分別是「服務 (程式名稱)、來源IP 或領域 或主機名稱、連線回應為允許 (allow) 或拒絕 (deny)」。區段間使用冒號(:)分隔。第三區段若省略,在hosts.allow內則為allow,在hosts.deny檔案內則為deny!另外在IP的遮罩部分,在ipv4的部分只支援255.255.255.0這樣的格式,不支援/24這類CIDR的表示方法!在ipv6則不在此限!
前二個區段中支援相關參數,但若使用 KNOWN、UNKNOWN、PARANOID 時,此三個參數是靠DNS名稱解析服務,因此須要注意主機的DNS名稱解析是否運作正常?
參數如下:
ALL: 表示 「全部 」,用於第一區段表示全部服務,用於第二區段(連線來源)表示全部來源。
LOCAL: 表示「本機」,也就是不含點 (.) 的主機名稱如localhost。
KNOWN: 表示「可解析主機」。
UNKNOWN: 表示「無法解析主機」。
PARANOID: 表示「正反解析必須一致」。
EXCEPT:「排除」的意思,例如允許 192.168.11.0 這個網段的所有主機,但排除 192.168.11.11 這個 IP 位址。
例如,在hosts.allow內設定允許192.168.11.0/255.255.255.0的網段但除了192.168.11.254這組ip連接sshd服務,其他的來源全部拒絕!這樣的設定可以只設定hosts.allow一個檔案,不需要再設定hosts.deny!
sshd: 192.168.11.0/255.255.255.0 EXCEPT 192.168.11.254 : allow
sshd: ALL : deny
1.由 super daemon (xinetd) 所管理的服務
2.僅適用 TCP daemon(有少數例外的狀況)
3.有支援libwrap.so模組的服務,可以用ldd指令來確認
ldd 判斷某個可執行的 binary 檔案含有什麼動態函式庫
-v :列出所有內容資訊;
-d :重新將資料有遺失的 link 點秀出來!
-r :將 ELF 有關的錯誤內容秀出來!
使用ldd查詢運行的服務是否有包含libwrap 函式庫,有包含的服務才能使用TCP Wrappers做控管,以下以sshd與postfix來做查詢:
$ ldd /usr/sbin/sshd |grep libwrap
libwrap.so.0 => /lib/x86_64-linux-gnu/libwrap.so.0 (0x00007f46028e5000)
sshd有查詢到使用libwrap 函式庫!
$ldd /usr/sbin/postfix |grep libwrap/etc/hosts.allow
postfix沒有查詢到使用libwrap 函式庫
因此TCP Wrappers只可以控管sshd,而無法控管postfix!
TCP Wrappers透過/etc/hosts.allow與/etc/hosts.deny兩個檔案來管理服務,順序如下:
1.先比對/etc/hosts.allow,若符合檔案內的設定規則就放行
2.若/etc/hosts.allow比對完後沒有符合的規則設定,再比對/etc/hosts.deny,若符合規則就阻擋
3.若依序比對完兩個檔案後都沒有符合的規則,最後還是放行!
/etc/hosts.allow與/etc/hosts.deny的檔案格式
<服務 (程式名稱)> : <來源IP 或領域 或主機名稱> : 允許 (allow) 或拒絕 (deny)
內容分成三個小區段來看,分別是「服務 (程式名稱)、來源IP 或領域 或主機名稱、連線回應為允許 (allow) 或拒絕 (deny)」。區段間使用冒號(:)分隔。第三區段若省略,在hosts.allow內則為allow,在hosts.deny檔案內則為deny!另外在IP的遮罩部分,在ipv4的部分只支援255.255.255.0這樣的格式,不支援/24這類CIDR的表示方法!在ipv6則不在此限!
前二個區段中支援相關參數,但若使用 KNOWN、UNKNOWN、PARANOID 時,此三個參數是靠DNS名稱解析服務,因此須要注意主機的DNS名稱解析是否運作正常?
參數如下:
ALL: 表示 「全部 」,用於第一區段表示全部服務,用於第二區段(連線來源)表示全部來源。
LOCAL: 表示「本機」,也就是不含點 (.) 的主機名稱如localhost。
KNOWN: 表示「可解析主機」。
UNKNOWN: 表示「無法解析主機」。
PARANOID: 表示「正反解析必須一致」。
EXCEPT:「排除」的意思,例如允許 192.168.11.0 這個網段的所有主機,但排除 192.168.11.11 這個 IP 位址。
例如,在hosts.allow內設定允許192.168.11.0/255.255.255.0的網段但除了192.168.11.254這組ip連接sshd服務,其他的來源全部拒絕!這樣的設定可以只設定hosts.allow一個檔案,不需要再設定hosts.deny!
sshd: 192.168.11.0/255.255.255.0 EXCEPT 192.168.11.254 : allow
sshd: ALL : deny
2017年7月25日 星期二
製作不用密碼即可登入的ssh用戶端
1.在ssh server上的欲接受遠端登入的帳號家目錄下製造Private Key與Public Key
ssh-keygen -t rsa -b 2048 #-t 指定使用rsa加密,-b 指定key的大小,單位bit,key越大越安全,但會影響建立連線的初始時間
$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa): <---詢問key存放位置
Enter passphrase (empty for no passphrase): <---輸入用來加密的密碼,不建議空白
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
3b:db:27:1e:d4:a8:7a:d5:3c:05:cb:09:3a:76:1c:a1 user1@ubuntu
The key's randomart image is:
+--[ RSA 2048]----+
| .. |
| .o . |
| Eo + + |
| + oo+ . |
| .Sooo.. |
| +. + |
| +.. . |
| ..+... |
| ....oo |
+-----------------+
2.指令會在使用者使用者家目錄下的.ssh內產生兩個檔案:id_rsa與id_rsa.pub,另外需注意,.ssh目錄權限必須為700,id_rsa檔案為600。
3.檢視ssh 伺服器上的sshd_config內AuthorizedKeysFile的設定值,這是設定公鑰要放置的位置與檔案名稱,一般應為%h/.ssh/authorized_keys,將公鑰放至指定的位置
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
必須確定.ssh目錄與authorized_keys檔案的擁有者與群組都必須與登入帳號吻合!
4.將id_rsa.pub檔案傳送到工作端上想登入ssh server的帳號家目錄.ssh資料夾下,可以使用scp來達成
cd ~
mkdir .ssh
chmod 700 .ssh
scp user@server:~/.ssh/id_rsa ~/.ssh/
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
必須確定.ssh目錄與authorized_keys檔案的擁有者與群組都必須與登入帳號吻合!
4.將id_rsa.pub檔案傳送到工作端上想登入ssh server的帳號家目錄.ssh資料夾下,可以使用scp來達成
cd ~
mkdir .ssh
chmod 700 .ssh
scp user@server:~/.ssh/id_rsa ~/.ssh/
5.測試可採用金鑰登入後,可取消ssh的密碼驗證,增加安全性
sudo vim /etc/ssh/sshd_config
PasswordAuthentication no
sudo vim /etc/ssh/sshd_config
PasswordAuthentication no
2017年5月4日 星期四
利用hosts.deny與hosts.allow來限制vsftp的連線
Linux預設安裝tcp_wrappers,所以可以利用/etc下的hosts.allow與hosts.deny來限制服務的連線!
格式:
服務名稱 : ip ip
以vsftpd來說,只允許192.168.11.0/24 192.168.12.0/24連線使用
在/etc/hosts.allow內加入:
vsftpd : 192.168.11.0/24 192.168.12.0/24
在/etc/hosts.deny內加入:
vsftpd : ALL
改完存檔後就會生效!但須注意,某些vsftp的預設值tcp_wrappers是沒有啟動的,會導致剛剛的設定不生效!需修改/etc/vsftpd.conf檔案,在裡面加入
tcp_wrappers=YES
存檔離開後,重新啟動vsftp,設定即會生效!
格式:
服務名稱 : ip ip
以vsftpd來說,只允許192.168.11.0/24 192.168.12.0/24連線使用
在/etc/hosts.allow內加入:
vsftpd : 192.168.11.0/24 192.168.12.0/24
在/etc/hosts.deny內加入:
vsftpd : ALL
改完存檔後就會生效!但須注意,某些vsftp的預設值tcp_wrappers是沒有啟動的,會導致剛剛的設定不生效!需修改/etc/vsftpd.conf檔案,在裡面加入
tcp_wrappers=YES
存檔離開後,重新啟動vsftp,設定即會生效!
2017年3月5日 星期日
Ubuntu 16.04 MariaDB外部連線
修改/etc/mysql/mariadb.conf.d/50-server.cnf內容,找到下列這行設定,並將其註解掉,如下:
#bind-address = 127.0.0.1
存檔後可以先看看目前Mariadb的服務監聽狀態:
$ netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
#bind-address = 127.0.0.1
存檔後可以先看看目前Mariadb的服務監聽狀態:
$ netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
一般將服務的設定檔變更後,只要重新啟動服務,應該就可以直接套用新的設定,但重新啟動了Mariadb,發現服務的監聽依然綁定在127.0.0.1:3306........只好使出殺手鐧~reboot......果然!在機器重新啟動後Mariadb的服務監聽不再是127.0.0.1:3306了!
$ netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN
2017年2月6日 星期一
Ubuntu 16.04 vsftp 設定
安裝:
sudo apt update
sudo apt-get install vsftpd
設定檔/etc/vsftpd.conf修改:
listen=YES
#listen_ipv6=YES #listen和listen_ipv6只能啟動一個,listen_ipv6支援ipv6與v4
# Allow anonymous FTP? (Disabled by default).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=002
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# If enabled, vsftpd will display directory listings with the time
# in your local time zone. The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
# Activate logging of uploads/downloads.
xferlog_enable=YES
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log
# You may restrict local users to their home directories. See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
chroot_local_user=YES
#以下這行沒設定,chroot user不能對自己的家目錄有寫入權限,會無法登入!
#以下這行沒設定,chroot user不能對自己的家目錄有寫入權限,會無法登入!
allow_writeable_chroot=YES
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list
# Customization
#
# Some of vsftpd's settings don't fit the filesystem layout by
# default.
#
# This option should be the name of a directory which is empty. Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
# Uncomment this to indicate that vsftpd use a utf8 filesystem.
utf8_filesystem=YES
Ubuntu 16.04 Mysql 5.7 max connections設定值大於214
修改/etc/mysql/mysql.conf.d/mysqld.cnf,設定需要的連線數:
max_connections=1000
再修改/lib/systemd/system/mysql.service,增加以下設定值:
LimitNOFILE=8192
接著執行以下指令:
systemctl daemon-reload
systemctl restart mysql.service
驗證:
進mysql後執行
show variables like "max_connections";
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
1 row in set (0.01 sec)
max_connections=1000
再修改/lib/systemd/system/mysql.service,增加以下設定值:
LimitNOFILE=8192
接著執行以下指令:
systemctl daemon-reload
systemctl restart mysql.service
驗證:
進mysql後執行
show variables like "max_connections";
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
1 row in set (0.01 sec)
2017年2月3日 星期五
Ubuntu 16.04 Mariadb phpmyadmin 安裝、登入
在Ubuntu 16.04安裝Mariadb 10+phpmyadmin;
先安裝Mariadb,apache2,php:
sudo apt update
sudo apt upgrade
sudo apt install mariadb-server mariadb-client apache2 php7.0 libapache2-mod-php7.0
Mariadb預設值卻不能登入phpmyadmin(mariadb預設空白密碼與預設禁止root登入phpmyadmin),在安裝完Mariadb後可進行以下修改:
變更Mariadb root密碼:
$ sudo mysqladmin -u root password
變更允許Mariadb root登入phpmyadmin
$ sudo mysql -u root -p mysql
先安裝Mariadb,apache2,php:
sudo apt update
sudo apt upgrade
sudo apt install mariadb-server mariadb-client apache2 php7.0 libapache2-mod-php7.0
Mariadb預設值卻不能登入phpmyadmin(mariadb預設空白密碼與預設禁止root登入phpmyadmin),在安裝完Mariadb後可進行以下修改:
變更Mariadb root密碼:
$ sudo mysqladmin -u root password
變更允許Mariadb root登入phpmyadmin
$ sudo mysql -u root -p mysql
use mysql;
update user set plugin='' where user='root';
flush privileges;
exit;
在安裝Mysql+phpmyadmin幾乎沒啥問題,但一把Mysql改成Maria總是一堆錯誤!phpmyadmin安裝時會在資料庫系統上產生一個phpmyadmin的資料庫與使用者帳號,但配合Maria時卻總是會失敗!懶得查詢phpmyadmin的安裝設定,直接取巧的先在Mariadb上手動新增phpmyadmin帳號(密碼:123456)與phpmyadmin資料庫,並給予phpmyadmin對phpmyadmin資料庫完整的權限:
$ sudo mysql -u root -p
create database phpmyadmin;
grant all on phpmyadmin.* to 'phpmyadmin'@'localhost' identified by '123456' with grant option;
接著再安裝phpmyadmin,應該可以順利安裝完成!
sudo apt install phpmyadmin
flush privileges;
exit;
在安裝Mysql+phpmyadmin幾乎沒啥問題,但一把Mysql改成Maria總是一堆錯誤!phpmyadmin安裝時會在資料庫系統上產生一個phpmyadmin的資料庫與使用者帳號,但配合Maria時卻總是會失敗!懶得查詢phpmyadmin的安裝設定,直接取巧的先在Mariadb上手動新增phpmyadmin帳號(密碼:123456)與phpmyadmin資料庫,並給予phpmyadmin對phpmyadmin資料庫完整的權限:
$ sudo mysql -u root -p
create database phpmyadmin;
grant all on phpmyadmin.* to 'phpmyadmin'@'localhost' identified by '123456' with grant option;
接著再安裝phpmyadmin,應該可以順利安裝完成!
sudo apt install phpmyadmin
訂閱:
文章 (Atom)