顯示具有 Service 標籤的文章。 顯示所有文章
顯示具有 Service 標籤的文章。 顯示所有文章

2017年3月18日 星期六

使用 systemd 操作 service - 列出所有受管理的項目

cy@cyvm:~$ systemctl status -all
● cyvm
    State: degraded
     Jobs: 0 queued
   Failed: 1 units
    Since: 六 2017-03-18 10:26:53 CST; 7h ago
   CGroup: /
           ├─init.scope
           │ └─1 /sbin/init splash
           ├─system.slice
           │ ├─avahi-daemon.service
           │ │ ├─859 avahi-daemon: running [cyvm.local
           │ │ └─931 avahi-daemon: chroot helpe
           │ ├─vboxadd-x11.service
...
cy@cyvm:~$ systemctl list-unit-files --all
UNIT FILE                                  STATE
proc-sys-fs-binfmt_misc.automount          static
dev-hugepages.mount                        static
dev-mqueue.mount                           static
proc-sys-fs-binfmt_misc.mount              static
sys-fs-fuse-connections.mount              static
sys-kernel-config.mount                    static
sys-kernel-debug.mount                     static
acpid.path                                 enabled
cups.path                                  enabled
systemd-ask-password-console.path          static
systemd-ask-password-plymouth.path         static
systemd-ask-password-wall.path             static
...

2017年1月24日 星期二

在 Ubuntu 上安裝 Samba Server

1. 安裝相關套件

sudo apt update
sudo apt upgrade
sudo apt install samba
sudo apt install libnss-winbind
其中,libnss-winbind 可讓 Linux 解析 Windows 的主機名。

2. 相關設定檔

2.1. smb.conf

/etc/samba/smb.conf

2.1.1. 一般使用者「家」目錄設定

[homes]
   comment = Home Directories
   browseable = yes
   read only  = no
   create mode    = 0600
   directory mode = 0700

2.2. nsswitch.conf

/etc/nsswitch.conf

2.2.1. 讓 Linux 解析 Windows 的主機名

hosts:          files mdns4_minimal [NOTFOUND=return] dns wins
在 hosts 後面多加一個 wins。

3. 資源管理

3.1. 新增使用者

sudo pdbedit -a -u user_name
其中,user_name為你要給定的使用者帳號名稱。
實作範例:
cy@cyvm:~$ sudo pdbedit -a -u cy
new password:
retype new password:
Unix username:        cy
NT username:
Account Flags:        [U          ]
User SID:             S-1-5-12-12345678-123456789-123456789-1234
Primary Group SID:    S-1-5-12-12345678-123456789-123456789-321
Full Name:            CY
Home Directory:       \\cyvm\cy
HomeDir Drive:
Logon Script:
Profile Path:         \\cyvm\cy\profile
Domain:               CYVM
Account desc:
Workstations:
Munged dial:
Logon time:           0
Logoff time:          三, 06  二  2036 23:06:39 CST
Kickoff time:         三, 06  二  2036 23:06:39 CST
Password last set:    二, 24  一  2017 23:46:36 CST
Password can change:  二, 24  一  2017 23:46:36 CST
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


4. 測試

4.1. 測試 smb.conf 設定是否正確

testparm
實作範例:
cy@cyvm:~$ testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
WARNING: The "syslog" option is deprecated
Processing section "[homes]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
        server string = %h server (Samba, Ubuntu)
        server role = standalone server
        map to guest = Bad User
        obey pam restrictions = Yes
        pam password change = Yes
        passwd program = /usr/bin/passwd %u
        passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
        unix password sync = Yes
        syslog = 0
        log file = /var/log/samba/log.%m
        max log size = 1000
        dns proxy = No
        usershare allow guests = Yes
        panic action = /usr/share/samba/panic-action %d
        idmap config * : backend = tdb


[homes]
        comment = Home Directories
        read only = No
        create mask = 0600
        directory mask = 0700
        directory mode = 0700


5. 服務管理

systemctl status smbd.service
systemctl restart smbd.service
systemctl enable smbd.service


2017年1月23日 星期一

在 Debian 安裝 SSH Server

1. 安裝相關套件

sudo apt-get update
sudo apt-get install openssh-server


2. 相關設定檔

2.1. sshd_config

/etc/ssh/sshd_config

2.1.1. 安全性設定

# What ports, IPs and protocols we listen for
Port 12345

SSH 預設使用 port 22,建議更改,特別在面向網路網路使用時,幾乎只要一上網就會被攻擊。埠號可自定,不要與使用中的埠號即可。

PermitRootLogin prohibit-password

建議不要使用 root 登入 SSH,所以可將 PermitRootLogin 設為 no。但讓 root 能登入有時候滿方便的,特別是有時需要傳一些需要 root 權限的檔案時,可以省掉一些操作上的麻煩。所以這裡使用 prohibit-password,再加上使用免密碼登入方式,就可以讓 root 能登入 SSH,且能保持一定程度的安全性。

#AllowUsers cy # NOTE! this will disable root login

可限定只有某些使用者登入,值得注意的是,若沒有加入 root,將會使 root 不能登入,即使 PermitRootLogin 為 yes 或 prohibit-password 亦然。在我的 Server 並未實作此項,所以前面加 #。

2.1.2. 效能性設定

UseDNS no

加了這個據說能加速登入速度。



3. 資源管理

3.1. 最好不要使用的帳號名

以下為我曾被攻擊的帳號名,最好不要使用這些帳號,特別是 admin:

0
0000
1111
1234
123456
adam
adm
admin
agent
anonymous
apache
bill
cisco
client
customer
default
edu
ftp
ftpuser
guest
jack
john
manager
mark
master
mike
nagios
operator
oracle
osmc
pi
plcmspip
raspberry
sales
scan
service
steve
super
support
Taiwan
test
testuser
tiffany
ubnt
uploader
user
user1
usuario
vyatta
www


4. 測試

4.1. ssh 登入測試:

cy@cyvm:~$ ssh -p 12345 cy@192.168.0.1

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
No mail.
Last login: Sat Mar 18 11:25:52 2017 from 192.168.0.2

4.2. ssh 登入測試:

cykuo@cyvm:~$ scp -P 12345 -i ~/keys/cy_ssh_key test.file root@192.168.0.1:~/root_work_dir
test.file                     100%  273     0.3KB/s   00:00


5. 服務管理

安裝完會自動啟動服務,其餘服務常用操作指令如下所列。

systemctl status sshd.service
systemctl restart sshd.service
systemctl enable sshd.service