密码登录
Ubuntu 系统的默认用户名是 ubuntu,并在安装过程中默认不设置 root 帐户和密码。您如有需要,可在设置中开启允许 root 用户登录。具体操作步骤如下:
-
首先另辟路径登上你的基于Ubuntu的服务器
-
执行命令,设置root密码
sudo passwd root
-
输入密码,重复输入密码,返回
passwd: password updated successfully
说明root密码设置成功 -
打开
sshd_config
配置文件,路径/etc/ssh/sshd_config
,具体的ssd_config
解析 -
找到
# Authentication:
修改PermitRootLogin yes
# Authentication: #LoginGraceTime 2m #PermitRootLogin prohibit-password # 禁止密码登录,只允许通过密钥登陆 PermitRootLogin yes #StrictModes yes #MaxAuthTries 6 #MaxSessions 10
-
修改
PasswordAuthentication
参数为yes
,没有就添加# To disable tunneled clear text passwords, change to no here! PasswordAuthentication yes #PermitEmptyPasswords no
-
重启ssh服务,
sudo service ssh restart
。或者重启服务器,或sudo systemctl restart sshd
-
然后就可以通过cmd窗口命令
ssh root@公网ip或域名 #但是域名得提前解析到公网ip
-
如果出现以下
WARNNING
,就把C:\\Users\\andya/.ssh/known_hosts:1
下的known_hosts
这个文件删掉@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the ECDSA key sent by the remote host is SHA256:W02kdKGXXmOYxdbdWRS4lj6GU0B+wBaL6VjmoiD6t6c. Please contact your system administrator. Add correct host key in C:\\Users\\andya/.ssh/known_hosts to get rid of this message. Offending ECDSA key in C:\\Users\\andya/.ssh/known_hosts:1 #这个路径!!! ECDSA host key for yanghe.life has changed and you have requested strict checking. Host key verification failed.