安装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 120PermitRootLogin without-passwordStrictModes yes
将PermitRootLogin without-password 修改为PermitRootLogin yes,如下:
# Authentication:LoginGraceTime 120PermitRootLogin yesStrictModes 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替换为你的密码,这样就开启了远程访问功能.