虚拟机安装ubuntu总结

一、首先设置root登录

1. 设置root的密码,sudo passwd -u root

虚拟机安装ubuntu总结

二、安装ifconfig

1. 下载ifconfig: sudo apt-get install net-tools

三、关闭防火墙

1. 安装sudo apt-get install ufw

虚拟机安装ubuntu总结

2. 查看防火墙状态:sudo ufw status

虚拟机安装ubuntu总结

3. 关闭防火墙:sudo ufw disable

虚拟机安装ubuntu总结

4. 开启/禁用相应端口或服务举例

sudo ufw allow 80 允许外部访问80端口
sudo ufw delete allow 80 禁止外部访问80 端口
sudo ufw allow from 192.168.1.1 允许此IP访问所有的本机端口
sudo ufw deny smtp 禁止外部访问smtp服务
sudo ufw delete allow smtp 删除上面建立的某条规则
sudo ufw deny proto tcp from 10.0.0.0/8 to 192.168.0.1 port 22 要拒绝所有的TCP流量从10.0.0.0/8 到192.168.0.1地址的22端口
虚拟机安装ubuntu总结

推荐设置

sudo apt-get install ufw
sudo ufw enable
sudo ufw default deny

这样设置已经很安全,如果有特殊需要,可以使用sudo ufw allow开启相应服务。

四、安装ssh

1. 下载:sudo apt-get install openssh-server

2. 启动:/etc/init.d/ssh start

3. 查看是否启动

虚拟机安装ubuntu总结


~~~~到这里,已经可以通过xshell连接了~~~~

但是还不能登录root用户

虚拟机安装ubuntu总结

下载编辑器vim:sudo apt-get install vim    查看版本:vim --version


下面开始设置从xshell登录root用户

1. 编辑这个文件:vim /etc/ssh/sshd_config 

将 PermitRootLogin改为yes:

虚拟机安装ubuntu总结

重启一下:sudo /etc/init.d/ssh restart

就可以登录了。