傻瓜式ssh操作
示例在xshell和vmware ubuntu20.04LTS下进行
查看IPv4地址
首先查看该虚拟机ip地址
ifconfig
如果你的虚拟机上没有安装net-tools的话会报错
Command 'ifconfig' not found, but can be installed with:
sudo apt install net-tools
那么就按照提示来安装一下
sudo apt install net-tools
装好之后执行ifconfig
即可,会出现
br-d84e0287a84b: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 172.18.255.255
ether 02:42:f7:11:84:dc txqueuelen 0 (以太网)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:4a:a1:e5:d6 txqueuelen 0 (以太网)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.127.138 netmask 255.255.255.0 broadcast 192.168.127.255
inet6 fe80::c397:c48e:6f35:b51 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:9d:c6:0f txqueuelen 1000 (以太网)
RX packets 1225 bytes 309776 (309.7 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 417 bytes 39356 (39.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 939 bytes 61287 (61.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 939 bytes 61287 (61.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
其中192.168.127.138
就是ip地址
Xshell下进行远程访问
开启Xshell后在terminal输入
ssh lcy@192.168.127.138
如果远程虚拟机的防火墙没有关闭或者ssh服务没有开启的话会报错连接失败
Connecting to 192.168.127.138:22...
Could not connect to '192.168.127.138' (port 22): Connection failed.
Type `help' to learn how to use Xshell prompt.
确认网络已开启
ping 192.168.127.138
如果ping通会显示
正在 Ping 192.168.127.138 具有 32 字节的数据:
来自 192.168.127.138 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.127.138 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.127.138 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.127.138 的回复: 字节=32 时间<1ms TTL=64
192.168.127.138 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
关闭防火墙
安装chkconfig
sudo apt-get install sysv-rc-conf
确认是否存在
ls /usr/sbin/ | grep sysv
改名
sudo cp /usr/sbin/sysv-rc-conf /usr/sbin/chkconfig
确认修改成功
ls /usr/sbin/ | grep chk
去对应目录下赋予权限
cd /usr/sbin
sudo chmod 755 chkconfig
关闭虚拟机上的防火墙
service iptables stop
sudo chkconfig iptables off
启动ssh服务
安装ssh
执行下面两条命令之一来进行安装(第一条可能会报错无法定位软件包sshd)
sudo apt-get install sshd
sudo apt-get install openssh-server
启动ssh
sudo service sshd start
检查SSHD是否在本运行级别下设置为开机启动
sudo chkconfig --list sshd
如果没有,则进行设置
sudo chkconfig --level 2345 sshd on
再次执行检查命令后可以看到
sshd 2:on 3:on 4:on 5:on
远程访问
在Xshell下再次输入ssh lcy@192.168.127.138
根据提示输入密码即可。