安装虚拟机Centos7
http://www.lotpc.com/zjjc/8936_3.html
文章引用内容
1.要确保CentOS7安装了 openssh-server,在终端中输入 yum list installed | grep openssh-server
yum list installed | grep openssh-server
2.如果又没任何输出显示表示没有安装,进行安装
yum install openssh-server
3.进入**/etc/ssh/** 目录下的sshd服务配置文件 sshd_config
cd /etc/ssh
用Vim编辑器打开
vi sshd_config
有可能会提示没有权限,切换到root用户
su root
然后重新进行上面操作,将文件中,关于监听端口、监听地址前的 # 号去除
编辑 sshd_config,然后点击“i”按键进入编辑模式,
vi sshd_config
一共修改3处,
第一处,打开端口22
第二处,开启允许远程登录
第三处,开启使用用户名密码来作为连接验证
保存文件,退出。
按esc键,然后输入':wq',回车退出
4.切换用户,
su qibin //su后输入自己的设置用户名
5.开启 sshd 服务,输入 sudo service sshd start
sudo service sshd start
可能会提示如下信息
[
解决:切换到root用户
su root
执行vi命令,编辑(按i键进行编辑)/etc/sudoers文件,添加要提升权限的用户,
vi /etc/sudoers //编辑文件命令
在文件中找到root ALL=(ALL) ALL,在该行下添加提升权限的用户信息
root ALL=(ALL) ALL
user ALL=(ALL) ALL //此处为添加内容,user为自己的用户名
6.保存退出,此处用强行保存
:wq!
7.此时再次运行sudo service sshd start命令
执行下面的命令:
//重启 sshd 服务
systemctl restart sshd.service
//设置服务开启自启
systemctl enable sshd.service
8.检查 sshd 服务是否已经开启,输入ps -e | grep sshd
ps -e | grep sshd
此时表示已开启
9.netstat -an | grep 22 检查 22 号端口是否开启监听
netstat -an | grep 22
到这里,设置基本完成。10.在Vmware Workstation中,点击编辑=>虚拟网络编辑器,进入虚拟网络编辑器,查看发现 NAT 模式的连接采用的网络适配器名称为VMnet8
11.在 windows 主机中,在命令行中输入ipconfig 查看主机IP,找到 VMnet8 的连接信息,此处 ip 为192.168.136.1
12.在CentOS7中,输入ifconfig查看网络连接地址,发现CentOS的网络地址为192.168.136.128
13.在CentOS7中,输入ping 192.168.136.1测试是否能连通主机,发现可以连通
14.在主机中,输入 ping 192.168.136.128,成功
如果不成功可以在主机,打开网络配置,选择网络适配器 VMnet8 的 TCP/IPv4 的属性,进行修改。15.在SSH工具(此处使用的MobaXterm)中,新建连接,输入 CentOS 的 IP 地址、用户名即可连接成功
16.为了免去每次开启 CentOS 时,都要手动开启 sshd 服务,可以将 sshd 服务添加至自启动列表中
//添加命令
systemctl enable sshd.service
//查看命令
systemctl list-unit-files | grep sshd