CentOS 7 在 Parallels 中的安装及基本配置

CentOS 7 在 Parallels 中的安装及基本配置_第1张图片
linux.jpg

本文介绍在 MacOS 上用 Parallels DeskTop 安装 CentOS 7 虚拟机以及安装之后的基本配置。基本配置包括:

  1. 配置静态 ip 并能够通过 SSH 连接
  2. 更换 yum 的源
  3. yum 安装基本软件
  4. 创建一个普通用户并赋予 root 权限

1. 安装 centos 7

首先下载镜像文件,我装的是 CentOS-7-x86_64-Minimal-1708.iso。我从网易的镜像下载,下载完后上传了一份到百度云盘:

网易镜像地址:http://mirrors.163.com/centos/7/isos/x86_64/
百度云盘链接:http://pan.baidu.com/s/1gf7w1uN 密码:5lbx

CentOS 7 在 Parallels 中的安装及基本配置_第2张图片
第一步
CentOS 7 在 Parallels 中的安装及基本配置_第3张图片
第二步

之后按照引导即可完成,有问题可以参看 Mac利用PD虚拟机安装Centos7

CentOS 7 在 Parallels 中的安装及基本配置_第4张图片
桥接模式

2. 配置静态 ip 并能够通过 SSH 连接

先看一下本机的网管和 ip,以我的为例:

ip 是: 192.168.2.126
网管是: 192.168.2.1

进入 CentOS 网卡的配置文件:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

在网卡中配置如下内容可以设置静态 ip

BOOTPROTO=static # 网卡获取IP的方式(默认为dchp,设置为静态获取。
IPADDR=192.168.2.20 # 除最后部分其他与宿主机的网关一致
GATEWAY=192.168.2.1 # 与宿主机保持一致
NETMASK=255.255.255.0

如果要访问外网还要配置 DNS

DNS1=192.168.2.1
DNS2=8.8.8.8

配置完之后保存重启网络

service network restart

之后就能通过 SSH 连接:

ssh [email protected]

4. 更换 yum 源

备份:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

去下面的源下载对应版本repo文件, 放入/etc/yum.repos.d/

repo文件下载地址:

网易:http://mirrors.163.com/.help/centos.html
阿里:http://mirrors.aliyun.com/repo/

运行以下命令生成缓存

yum clean all
yum makecache

yum 源配置完成

3. 通过 yum 安装一些基本软件

net-tools 提供dig, nslookup, ipconfig等,用于配置网络:

yum install net-tools

添加 wget 下载文件:

yum install wget

4. 创建一个普通用户并赋予 root 权限

用普通账号进行登录可以避免 root 用户进行错误操作,而且用普通用户登录就像给服务器建立了两道墙,必须先用普通用户登录再设置能用 root 账号登录,所以后面还要配置禁止 root 用户用过 SSH 登录。

创建普通用户

useradd shui
passwd shui
输入密码

这个普通用户有时也需要使用 root 权限,所以讲他加入到sudoers 用户组,允许其使用sudo临时调用 root 权限

echo 'shui ALL=(ALL) ALL'>> /etc/sudoers
tail -1 /etc/sudoers
shui ALL=(ALL) ALL

更多权限管理可以看另一篇 Linux 权限管理

5. 禁止 root 使用 ssh 登入

进入配置文件:

/etc/ssh/sshd_config

找到如下语句进行修改

PermitRootLogin yes

把它改成

PermitRootLogin no

重启 sshd

systemctl restart sshd.service

这样别人就要必须要获取普通用户账号密码,然后才能破解 root

6. 将防火墙换成 iptables

CentOS 7.0 默认使用的是 firewall 作为防火墙,常用的是 iptables。先关闭 firewall 再安装 iptables。

关闭 firewall

#停止firewall
systemctl stop firewalld.service 
#禁止firewall开机启动
systemctl disable firewalld.service 

安装 iptables

yum -y install iptables-services

启动 iptables

#重启防火墙使配置生效
systemctl restart iptables.service 
#设置防火墙开机启动
systemctl enable iptables.service 

参考:

CentOS yum 源的配置与使用

安裝 CentOS 7 後必做的七件事

你可能感兴趣的:(CentOS 7 在 Parallels 中的安装及基本配置)