# Ubuntu

# 虚拟机安装

  • 下载VirtualBox软件和ubuntu系统镜像
  • 选择最小化安装,虚拟机网络设置桥接网卡(注意这里)
  • 如果选择的是NAT 网络地址转换,那么请将虚拟机端口映射到主机端口

# 换源

cd /etc/apt/
rm -r sources.list && touch sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse" >> sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse" >> sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse" >> sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse" >> sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse" >> sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse" >> sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse" >> sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse" >> sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse" >> sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse" >> sources.list
apt update  && apt upgrade  -y

# 重装编辑器

apt remove vim-common
apt install vim

# 配置网络

  • 设置网络(主要是为了固定 IP)

cd /etc/netplan/
# 01-network-manager-all.yaml
network:
  version: 2
  renderer: NetworkManager
  ethernets:
          enp7s0:
                  dhcp4: no
                  addresses: [192.168.4.198/24]
                  gateway4: 192.168.4.1
                  nameservers:
                           addresses: [223.5.5.5, 223.6.6.6, 119.29.29.29]
  wifis:
          wlp8s0:
                  dhcp4: yes
                  access-points:
                      'wifi-ssid':
                         password: wifi-password

netplan apply
  • 重启网络

# 以下命令均可重启网络
# 1 service
sudo service network-manager restart
# 2 systemctl
# systemctl restart NetworkManager.service
# 3 nmcli (不要在服务器上使用这招)
# sudo nmcli networking off
# sudo nmcli networking on
# 查看ip地址
ip addr

# 安装 SSH 服务

apt install openssh-server -y
# 或者 yum install sshd
systemctl start sshd
systemctl enable sshd
  • 略过一些非必要操作(这一步一般不会出现问题,有问题百度即可)
  • 安装完 ssh 就可以全程在本地操作了,服务器挂着就行。
  • 配置 SSHkey 免密码登录,或者使用 SSH 管理软件保存密码

# 客户端生成sshkey,并上传公钥到服务端
ssh-keygen
ssh-copy-id root@192.168.a.xxx

注意: 最后记得备份系统以备不时之需