虚拟机我使用的是VMware12,新建虚拟机过程简单,ubuntu server16在安装虚拟机的时候比较简单,在新建的时候就要求输入用户名密码,这样虚拟机新建的时候就无需值守,机器全部帮你做好,很方便。
安装完成到使用xshell连接,还需要一些操作,这里做一些记录。
配置子网IP
为了以后xshell就能使用固定ip连接虚拟机
点击编辑 -> 虚拟机网络编辑器
点击右下的更改配置
修改NAT模式的子网ip,虚拟机在在配置的时候网络适配器就选择的是NAT模式。
右边的 NAT设置
也可以点开看下,
这里的子网掩码、网关ip后面在设置静态ip的时候要一致。
修改静态ip
上面改的是子网的ip段,这里需要改具体的ip,ubuntu下修改的是下面的文件,其他的系统不一定是一样的。
使用命令 sudo vi /etc/network/interfaces
我的打开后是下面这样的
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens32
iface ens32 inet dhcp
从最后一行的dhcp
开始改,
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens32
iface ens32 inet static
address 192.168.1.8
netmask 255.255.255.0
gateway 192.168.1.2 # 这个网关要和你前面的NAT模式一致
重启一下虚拟机(重启网卡似乎没生效)
安装配置 openssh-server
sudo apt-get install openssh-server
安装后openssh-server
会自动启动,也可以通过ps -ef | grep ssh
查看。到这里Xshell应该可以连接到你创建的用户了,但是并不能 root
用户连接,原因有1、此时并没有创建 root
用户密码;2、openssh默认不允许root直连,进行如下操作:
1. sudo passwd root
配置 root
用户密码,
2. sudo vi /etc/ssh/sshd_config
可以找到一行 PermitRootLogin without passwd
修改为 PermitRootLogin yes
,后面的改为yes就行了
3. service ssh restart
重启一下ssh
配置用户密码之后也可以普通用户登录,然后使用 su
切换为 root
用户。
这样配置基本完成了,有需要的可以修改一下源,国内我觉得ali的源还是挺好用的,其他如163的源也行。