默认root没有密码,官方说不需要设置root密码,不能用root 登录,也不能用su 切换到root。如果用 sudo passwd root 给 root 设置密码后就启用root了。
SSH 设置
安装 SSH Server
默认没有安装 ssh server。安装命令:sudo apt install openssh-server,查看 sshd 的状态:sudo service ssh status 或者 sudo systemctl status sshd 。
设置 SSH监听端口为9001
修改配置文件,sudo vim /etc/ssh/sshd_confi``g
第5行,原来是 Port 22, 改成 Port 9001
1 # Package generated configuration file2 # See the sshd_config(5) manpage for details34 # What ports, IPs and protocols we listen for5 Port 90016 # Use these options to restrict which interfaces/protocols sshd will bind to7 #ListenAddress ::8 #ListenAddress 0.0.0.09 Protocol 210 # HostKeys for protocol version 211 HostKey /etc/ssh/ssh_host_rsa_key12 HostKey /etc/ssh/ssh_host_dsa_key13 HostKey /etc/ssh/ssh_host_ecdsa_key14 HostKey /etc/ssh/ssh_host_ed25519_key15 #Privilege Separation is turned on for security16 UsePrivilegeSeparation yes1718 # Lifetime and size of ephemeral version 1 server key19 KeyRegenerationInterval 360020 ServerKeyBits 10242122 # Logging23 SyslogFacility AUTH24 LogLevel INFO2526 # Authentication:27 LoginGraceTime 12028 PermitRootLogin prohibit-password29 StrictModes yes3031 RSAAuthentication yes32 PubkeyAuthentication yes33 #AuthorizedKeysFile %h/.ssh/authorized_keys3435 # Don't read the user's ~/.rhosts and ~/.shosts files36 IgnoreRhosts yes37 # For this to work you will also need host keys in /etc/ssh_known_hosts38 RhostsRSAAuthentication no39 # similar for protocol version 240 HostbasedAuthentication no... ...
第 28 行,PermitRootLogin prohibit-password,意思是不允许远程用 root 的密码方式登录
重启 sshd 生效,命令: sudo service ssh restart 或者 sudo systemctl restart sshd.service
防火墙开放端口
默认 UFW 已经安装,但是没有 enable, 启用 UFW,命令: sudo ufw enable
- 开放某端口
sudo ufw allow 9001 - 关闭开放的端口:
sudo ufw delete allow 9001 - 查看开放了哪些端口:
sudo ufw status - 用编号显示开放的端口:
sudo ufw status numbered - 用编号删除开放的端口:
sudo ufw delete 2IP 操作
查看 IP 命令ip address修改 IP
sudo vim /etc/network/interfaces,修改完理论上重启网络服务生效,命令:sudo systemctl restart networking.service。但是发现重启网络服务后查看IP,原来的 IP 和 新的 IP 都显示了。重启电脑后解决,命令 :sudo reboot
