# 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
# 重装编辑器
默认的 vim 编辑器存在键盘适配的问题
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
systemctl start sshd
systemctl enable sshd
- 略过一些非必要操作(这一步一般不会出现问题,有问题百度即可)
- 安装完 ssh 就可以全程在本地操作了,服务器挂着就行。
- 配置 SSHkey 免密码登录,或者使用 SSH 管理软件保存密码
# 客户端生成sshkey,并上传公钥到服务端
ssh-keygen -C '[email protected]'
ssh-copy-id [email protected]
注意: 最后记得备份系统以备不时之需