機器的遠程訪問僅限使用公鑰與Yubico4/NEO實體公鑰進行SSH認證。php
出於安全考慮,節點不該在共享的機器上運行,而應在Deltalis, Equinix及A1 Arsenal等安全性較高的數據中心經過託管的方式運行。下列laaS供應商硬件配置可做爲2018年的理想配置參考。html
由於共識節點有計算功能,所以應按期檢查網絡硬件要求以保證最優性能。node
若是沒法進行託管,推薦laaS供應商與最低配置以下:git
使用密碼管理工具存放本次搭建過程當中所需的每一個密碼(推薦使用Lastpass和Dashlane),全部服務均應啓用雙因素認證和實體密鑰(若有)。github
全部密碼均應設置高強度密碼(使用此 lastpass方案)。web
僅限使用公鑰訪問SSH認證可起到密鑰保護的做用,因此咱們要求使用實體OpenPGP智能卡進行SSH認證。咱們推薦使用Ubikey 4。有關Yubikey PGP的更多性能請參考官方文檔.sql
更改默認管理員PIN碼 12345678
與PIN碼 123456
爲可記憶的安全密碼。shell
將您的私鑰添加到智能卡激活的認證代理服務後,gpg-agent就會與gpg2綁定——這是咱們推薦的步驟。數據庫
打開供應商防火牆(不在OS設置中),設置爲屏蔽所有,端口2二、20333與10333除外。如有其餘服務共享同一帳戶,請務必確保將節點放置在反關聯性羣組中。json
需給每一個節點在兩個轄區分別配置2個管理員。每一個管理員都應有一個能夠登陸系統的專屬用戶和一個(SSH無權訪問的)第三方共識用戶,而且僅可經過該第三方共識用戶訪問共識節點的私鑰(注意本指南使用的Ubuntu版本是16.04 LTS)。
首次登陸時,設置一個強效根密碼,但僅在遺失sudo密碼(或進行撤銷操做)時才需使用根密碼;
su (sudo su on Ubuntu)
passwd複製代碼
Ubuntu更新包:
apt-get update
apt-get upgrade複製代碼
CentOS:
yum update複製代碼
添加管理員用戶(兩個管理員重複操做):
useradd -m node
mkdir /home/node/.ssh
chmod 700 /home/node/.ssh複製代碼
本指南是基於bash編制的,因此在shell下拉列表中將bash設爲偏好值:
usermod -s /bin/bash node複製代碼
從管理員的 ssh-add -L
中將Yubikey公鑰複製到authorized_keys:
vim /home/node/.ssh/authorized_keys複製代碼
許可設置:
chmod 400 /home/node/.ssh/authorized_keys
chown node:node /home/node -R複製代碼
設置管理員密碼(這就是sudo密碼):
passwd node複製代碼
接下來咱們就能夠設置管理員的sudo了,添加 %sudo
羣組,註釋非 root
的任何其餘羣組時使用#:
visudo複製代碼
文件格式以下:
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
#%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d複製代碼
將管理員添加到sudo羣組:
usermod -aG sudo node複製代碼
需登陸並登出管理員帳戶後才能完成更新:
su -l node
exit複製代碼
再回到su,如今設置爲僅可經過公鑰與管理員登陸SSH:
vim /etc/ssh/sshd_config複製代碼
應添加下列行或在原有的基礎上修改爲以下形式,在AllowUsers中添加全部管理員並用空格鍵隔開:
X11Forwarding no
PermitRootLogin no
PasswordAuthentication no
AllowUsers node
LoginGraceTime 30
AllowTcpForwarding no
TCPKeepAlive no
AllowAgentForwarding no
DebianBanner no
Banner /etc/ssh/sshd-banner複製代碼
設置SSH的法律聲明:
echo "WARNING: Unauthorized access to this system is forbidden and will be prosecuted by law. By accessing this system, you agree that your actions may be monitored if unauthorized usage is suspected." >> /etc/ssh/sshd-banner複製代碼
添加用戶運行共識節點:
useradd consensus
mkdir /home/consensus
chown consensus:consensus /home/consensus -R複製代碼
爲共識節點建立一個很是強效的密碼,應可安全地被兩個管理員共享:
passwd consensus複製代碼
su的最後一步就是以管理員身份登陸後重啓SSH。
sudo systemctl restart sshd.service複製代碼
首先在Debian(Ubuntu)中安裝防火牆並鎖定節點:
sudo apt-get install ufw複製代碼
CentOS:
sudo yum install epel-release
sudo yum install ufw複製代碼
在vim /etc/default/ufw
中將IPV6設爲yes,並設置爲僅容許使用端口:
sudo ufw default deny incoming
sudo ufw allow ssh
sudo ufw allow 10333
sudo ufw allow 20333
sudo ufw disable
sudo ufw enable複製代碼
sudo apt-get install unattended-upgrades
sudo vim /etc/apt/apt.conf.d/10periodic複製代碼
更新以匹配:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";複製代碼
禁止不安全的自動更新:
sudo vim /etc/apt/apt.conf.d/50unattended-upgrades複製代碼
更新,未註釋的行有且僅有如下幾行:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}ESM:${distro_codename}";
};複製代碼
安裝yum-cron並容許安全包更新:
sudo yum -y install yum-cron
sudo systemctl start yum-cron
sudo systemctl enable yum-cron
sudo nano /etc/yum/yum-cron.conf複製代碼
更改設置以匹配:
update_cmd = security
apply_updates = yes
emit_via = email
email_to = YOUR_EMAIL_TO_RECEIVE_UPDATE_NOTIFICATIONS複製代碼
有更新時,使用email_to功能插入你想發送提醒的郵件地址。
接下來咱們就來安裝fail2ban,這個工具可禁止防火牆上的可疑IP。該工具的默認值就可以使用,所以簡單的安裝就夠了。Ubuntu:
sudo apt-get install fail2ban複製代碼
CentOS:
sudo yum install fail2ban複製代碼
將2FA與SSH的實體OpenPGP密鑰相結合是強效認證設置。在Ubuntu中使用下列代碼安裝:
sudo apt-get install libpam-google-authenticator複製代碼
CentOS (啓用epel——同上):
sudo yum install google-authenticator複製代碼
安裝完畢後,以管理員身份運行指令時遵循每步指令,(回答y/y/y/n/y),先以管理員身份(兩個)進行這步操做,完成後再更新PAM得到2FA:
google-authenticator複製代碼
接下來編輯SSH配置來得到2FA設置許可:
sudo vim /etc/pam.d/sshd複製代碼
在文件結尾添加如下行:
auth required pam_google_authenticator.so複製代碼
在Ubuntu中放入密碼提示的註釋行:
# Standard Un*x authentication.
#@include common-auth複製代碼
CentOS:
#auth substack password-auth複製代碼
編輯sshd_config文件要求進行2FA認證:
sudo vim /etc/ssh/sshd_config複製代碼
編輯文件容許認證,並添加認證方法行:
ChallengeResponseAuthentication yes
AuthenticationMethods publickey,password publickey,keyboard-interactive複製代碼
重啓SSHD服務:
sudo systemctl restart sshd.service複製代碼
在保持當前SSH窗口運行的同時打開另外一個窗口,並登陸以確認設置能正確運行。
保持對共識節點的監視對於發現問題及改善NEO項目而言是相當重要的。咱們僅會經過SSH通道安裝並訪問網絡數據庫(保留防火牆攔截設置)。
安裝預購建靜態版本(以減小攻擊面並杜毫不必要的依賴性):
bash <(curl -Ss https://my-netdata.io/kickstart-static64.sh)複製代碼
訪問方法是建立SSH通道並打開瀏覽器訪問localhost:19999:
ssh -f node@SERVERIP -L 19999:SERVERIP:19999 -N複製代碼
sudo apt-get install mailutils複製代碼
CentOS:
sudo yum install mailx複製代碼
編輯默認bash檔案:
sudo vim /etc/profile複製代碼
在文件結尾添加如下行,編輯郵箱使其可接收登陸通知:
SIP="$(echo $SSH_CONNECTION | cut -d " " -f 1)"
SHOSTNAME=$(hostname)
SNOW=$(date +"%e %b %Y, %a %r")
echo 'Someone from '$SIP' logged into '$SHOSTNAME' on '$SNOW'.' | mail -s 'SSH Login Notification' 'YOUR@EMAIL.HERE'複製代碼
在Ubuntu上配置logwatch以發送節點的平常活動總結(一般無活動):
sudo apt-get install logwatch複製代碼
CentOS:
sudo yum install logwatch複製代碼
如今添加cron job將總結髮送到你的郵箱:
sudo vim /etc/cron.daily/00logwatch複製代碼
將默認執行命令變動爲:
/usr/sbin/logwatch --output mail --mailto YOUR@EMAIL.HERE --detail high複製代碼
咱們會把不須要的模塊放入黑名單以減小攻擊面,WiFi和藍牙一般已經與服務器內核切斷了(需驗證!),所以僅需關閉USB存儲。
sudo vi /etc/modprobe.d/blacklist.conf複製代碼
添加如下行:
blacklist usb-storage
blacklist firewire-core複製代碼
在Unbuntu上安裝前提條件:
sudo apt-get install unzip sqlite3 libsqlite3-dev libleveldb-dev libunwind-dev複製代碼
CentOS:
sudo yum install unzip leveldb-devel libunwind-devel複製代碼
以共識節點用戶的身份登陸:
su consensus
cd ~複製代碼
在發行版中下載、驗證校驗和、解壓最新版neo-cli客戶端:
wget https://github.com/neo-project/neo-cli/releases/download/v2.5.2/neo-cli-YOURDISTRIBUTION.zip
sha256sum neo-cli-YOURDISTRIBUTION.zip
unzip neo-cli-YOURDISTRIBUTION.zip
cd neo-cli
chmod u+x neo-cli複製代碼
複製節點運行的設置(測試網或主網):
mv protocol.json protocol.json.back
cp protocol.testnet.json protocol.json複製代碼
若是這是首次操做,你須要給共識節點建立錢包:
./neo-cli
neo> create wallet /home/consensus/cn_wallet.json
password: SOMESTRONGPASSWORD
password: SOMESTRONGPASSWORD複製代碼
複製start_consensus腳本:
cd ~
wget https://raw.githubusercontent.com/CityOfZion/standards/master/assets/nodes/start_consensus.sh
chmod u+x start_consensus.sh複製代碼
編輯目錄使其與你的錢包文件地址及密碼匹配。如今就能夠在supervisord的控制下在Ubuntu上運行了:
sudo apt-get install supervisor複製代碼
CentOS:
sudo yum install supervisor複製代碼
配置supervisord以執行start_consensus(在須要的狀況下編輯文件):
wget https://raw.githubusercontent.com/CityOfZion/standards/master/assets/nodes/supervisord.conf
chmod 700 supervisord.conf
cp supervisord.conf /etc/supervisord.conf
sudo supervisord複製代碼
添加初始腳本以便在系統重啓時自動運行。
這就是所有步驟,如今登出服務器並僅在必須部署更新或檢測到惡意行爲時再從新登陸。
原文翻譯自CoZ:github.com/CityOfZion/…