一天一点linux(8):ubuntu安装后ssh无法连接怎么解决?

安装Ubuntu后,想用root用户远程连接虚拟机,但是一直连不上,找了找资料,原来ubuntu 服务器默认的root账号是没有激活的,需要用初装的用户账号给root设置管理密码:

user@silk:~$sudo passwd root//用sudo修改root帐户
Password: //输入密码
Enter new UNIX password: //提示输入新的root帐户密码
Retype new UNIX password: //再输入一次确认密码

修改成功之后你就可以使用root账号了,可以使用su root 命令切换到root。

root@silk#:su root
密码:

但是碰到过一次情况,就是修改之后,直接用root账号无法登陆远程终端,这是还需要修改ssh配置文件:
/etc/ssh/sshd_config 修改该配置文件:

# Authentication:
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes

将PermitRootLogin without-password 修改为PermitRootLogin yes,如下:

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

然后,重启下ssh服务,

/etc/init.d/ssh restart

可以成功登陆了。
备注:
查看防火墙状态

sudo ufw status

查看sshserver是否启动:(或用“netstat -tlp”命令,查看端口号22)

ps -e | grep ssh

开启远程访问mysql数据库

grant all on sonardb.* to root@localhost identified by '123456';

sonardb替换为你想访问的数据库名,root是你的想使用的用户名,123456替换为你的密码,这样就开启了远程访问功能.

    原文作者:denson
    原文地址: https://segmentfault.com/a/1190000004561437
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞