step1:ubuntu16装系统的过程略过
step2: 联网
step3:apt-get更新
sudo apt-get update
step4:安装ssh
# 安装 openssh 服务
sudo apt-get install openssh-server
# 启动 ssh 服务
sudo /etc/init.d/ssh start
step5: ubuntu开启22端口
虽然可以用命令 systemctl stop firewalld和systemctl disable firewalld 直接关闭防火墙,但不建议这样做,推荐仅允许22端口通过防火墙:
# 若 firewalld 未安装,则先进行安装
sudo apt install firewalld
# 允许 tcp 22端口
sudo firewall-cmd --permanent --add-port=22/tcp
# 可选:允许ssh服务
sudo firewall-cmd --permanent --add-service=ssh
# reload 防火墙,应用规则
sudo systemctl reload firewalld
验证22端口是否开启:
sudo firewall-cmd --list-all
若结果中含有22端口,表示已开启:
如果要卸载防火墙:
sudo apt-get remove iptables # 卸载防火墙