ubuntu默认关闭了root账户,可根据实际情况开启或关闭root登录。
ubuntu@localhost:~$ sudo apt install openssh-server
ubuntu@localhost:~$ sudo passwd root
New password: 【输入密码】
Retype new password:【输入密码】
ubuntu@localhost:~$ sudo vim /etc/ssh/sshd_config
……
Port 22 #SSH端口
……
PermitRootLogin yes #允许root用户登录
#PermitRootLogin no #禁止root用户登录
PasswordAuthentication yes #允许密码登录
#PasswordAuthentication no #禁止密码登录,如使用公钥登录
……
ubuntu@localhost:~$ sudo systemctl restart sshd #重启sshd服务
建议修改dns为国内主流dns服务商地址,如阿里云dns。
root@localhost:~# vi /etc/netplan/50-cloud-init.yaml
network:
ethernets:
eth0:
addresses:
- 172.24.8.111/24
dhcp4: false
gateway4: 172.24.8.2
nameservers:
addresses:
- 223.5.5.5 #DNS修改为阿里云公共dns
search: []
version: 2
建议修改apt源为国内主流apt提供商地址,如阿里云apt源。
root@localhost:~# sudo vim /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
root@localhost:~# apt-get update && apt-get upgrade -y && apt-get autoremove -y
root@localhost:~# sudo apt-get -y install net-tools vim wget ntp bash-completion build-essential gcc openssh-client lvm2 make terminator git ssh lrzsz htop
以上主要为一些服务器相关软件,可根据实际情况安装必要组件。
root@localhost:~# sudo vi /etc/default/locale
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh" #设置为中文
LANG="en_US.UTF-8"
LANGUAGE="en_US:en" #需要为英文
root@localhost:~# adduser xianghy #填写相关信息创建用户
[root@client ~]# ssh xianghy@172.24.8.111 #客户端测试登录
xianghy@172.24.8.111's password: 【输入密码】
[root@client ~]# ssh-keygen -f ~/.ssh/xianghy_key -N '' #客户端创建私钥
[root@client ~]# ssh-copy-id -i ~/.ssh/xianghy_key.pub xianghy@172.24.8.111 #上传公钥至服务端
[root@client ~]# vim ~/.ssh/config
Host xianghyhost #主机别名
HostName 172.24.8.111 #服务端IP
Port 22 #服务端SSH端口
User xianghy #服务端用户名
IdentityFile ~/.ssh/xianghy_key #私钥文件路径
[root@client ~]# chmod 600 ~/.ssh/config
[root@client ~]# ssh xianghyhost #使用别名登录测试
root@localhost:~# systemctl stop ufw.service
root@localhost:~# systemctl disable ufw.service
参考:《001.Chrony时间服务器》