2017年11月16日 星期四

點陣印表機無法列印

今天一早(21071116)就接到user反應點陣式印表機無法列印.....還不只單一個案,有些是整個辦公室都有相同的問題,作業系統涵括windows 7與windows 10......檢查許久還是找不到問題!便開始懷疑是否是更新造成?一檢查,windows7與windows 10今天各有兩支更新被安裝!嘗試著先移除一支試試!Bingo!!抓到兇手了.....
在windows7下的KB4048957與windows10下的KB4048954,KB4048955(兩隻都會造成異常,有看到就移除!)這兩支更新程式一移除,一切都正常了......😤
移除程式,重新開機後,記得到windows update內去把這支更新隱藏,不然會再自動重新安裝......😔

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

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,或者直接註解掉這一行!

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的代理!!




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



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/

5.測試可採用金鑰登入後,可取消ssh的密碼驗證,增加安全性
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,設定即會生效!

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

一般將服務的設定檔變更後,只要重新啟動服務,應該就可以直接套用新的設定,但重新啟動了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不能對自己的家目錄有寫入權限,會無法登入!
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)

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
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