ずっと、FreeBSD使ってきたけど、なにかとFreeBSDで動かないものとか多くていまいちなので、
FreeBSD使ってきた人がDebian使い始めるmemo
と、言っても事の発端はAnsibleでZABBIX4構築するためなので、初期設定もAnsible使ってみました。
Ansibleの導入
標準だとAnsibleのバージョンが古いため、Ubuntu PPAで配布されているものを利用します。
(参照:https://docs.ansible.com/ansible/2.5/installation_guide/intro_installation.html#latest-releases-via-apt-debian)
deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main
# apt update
# apt install dirmngr
# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
# apt install ansible
Playbookの作成
AnsibleのPlaybookを作ります。
---
- hosts: localhost
user: root
vars:
admin_name: USER
admin_password: PASSWORD
admin_public_key_path: ~/.ssh/id_rsa.pub
tasks:
- name: set timezone to Asia/Tokyo
timezone:
name: Asia/Tokyo
- name: Install sudo
apt:
name: sudo
- name: Install ufw
apt:
name: ufw
- name: Deny everything and enable UFW
ufw:
state: enabled
policy: deny
- name: Set logging
ufw:
logging: on
- name: Accept SSHd
ufw:
rule: limit
port: ssh
proto: tcp
- name: disallow root SSH access
lineinfile:
dest: /etc/ssh/sshd_config
regexp: "^PermitRootLogin "
insertafter: "^#PermitRootLogin"
line: "PermitRootLogin no"
state: present
- name: disallow password authentication
lineinfile:
dest: /etc/ssh/sshd_config
regexp: "^PasswordAuthentication "
insertafter: "^#PasswordAuthentication "
line: "PasswordAuthentication no"
state: present
- name: Add a new user
user: name={{admin_name}} password={{ admin_password }} state=present group=sudo
- name: resister a public key
authorized_key:
user={{ admin_name }}
key="{{ lookup('file', '/root/.ssh/authorized_keys') }}"
- name: restart sshd
service: name=sshd state=restarted
Playbookの適用
localhostの後のカンマがミソらしい
# ansible-playbook -i localhost, -c local setup.yml
細かいところ
そのうち、Ansibleにまとめます。
コマンド履歴の前方一致
FreeBSDだと、過去に入力したコマンドの一部を入力し、上カーソルを押すと、
前方一致で履歴表示するけど、Debianはそうもいかない。
ホームディレクトリの.inputrcに次の設定を入れると同じようになる。
"\e[A":history-search-backward
"\e[B":history-search-forward
ll が使えるようにする
alias ll='ls -l --color=auto'
外にメールを投げられるようにする
FreeBSDだとSendmailが入ってて、SmartHostを設定すれば、sendmailコマンドから
メールが投げられるけど、Debianだとそういうの無いみたいで、ssmtpを使うといいっぽい
# apt get install ssmtp
手元の環境では、認証必要ないSMTPサーバがいるのでこんな感じ
mailhub=RelayHost:25
hostname=ThisHostName