机器的远程访问仅限使用公钥与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
Ubuntu:
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}"; };
CentOS:
安装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:https://github.com/CityOfZion/standards/blob/master/nodes.md