![97b347cc468b98a819f4b1a801f26c27.png](https://i-blog.csdnimg.cn/blog_migrate/53c4eba00337936bd76b7bd5e651a678.png)
![ba8153d5af55281a2c9b8b4475a0b210.png](https://i-blog.csdnimg.cn/blog_migrate/64b4bf82dec68607f20c2a40305f7e81.jpeg)
1、设置root用户(Ubuntu16)
【1】默认没有开启root用户,切换root如下所示
dk@dk-machine:~$ su root密码: su:认证失败dk@dk-machine:~$
使用命令sudo passwd root
,然后输入用户名和密码,接下来输入root用户的密码并确认,然后使用命令su root
,输入root的密码后,既转为root用户:
dk@dk-machine:~$ sudo passwd root[sudo] dk 的密码: 输入新的 UNIX 密码: 重新输入新的 UNIX 密码: passwd:已成功更新密码dk@dk-machine:~$ su root密码: root@dk-machine:/home/dk#
【2】修改配置文件
root@dk-machine:/home/dk# cd /usr/share/lightdm/lightdm.conf.d/root@dk-machine:/usr/share/lightdm/lightdm.conf.d# ls50-disable-log-backup.conf 50-guest-wrapper.conf 50-unity-greeter.conf50-greeter-wrapper.conf 50-ubuntu.conf 50-xserver-command.confroot@dk-machine:/usr/share/lightdm/lightdm.conf.d# gedit 50-unity-greeter.conf
改文件原来的内容如下:
[Seat:*]greeter-session=unity-greeter
修改为:
[Seat:*]greeter-session=unity-greeteruser-session=ubuntugreeter-show-manual-login=trueall-guest=false
用root用户在图形界面登录有错误—-读取/root/.profile时发生错误:mesg:tty n还需要做如下修改:
使用命令gedit /root/.profile
打开该文件
# ~/.profile: executed by Bourne-compatible login shells.if [ "$BASH" ]; then if [ -f ~/.bashrc ]; then . ~/.bashrc fifimesg n || true
修改为
# ~/.profile: executed by Bourne-compatible login shells.if [ "$BASH" ]; then if [ -f ~/.bashrc ]; then . ~/.bashrc fifitty -s && mesg n || true
保存重启,之后点击登陆,输入root,然后输入root密码即可使用root登陆。
1、设置root用户(Ubuntu18)
- 打开文件
/etc/pam.d/gdm-autologin
将auth required pam_succeed_if.so user != root quiet_success
注释, 保存。 - 打开文件
/etc/pam.d/gdm-password
将auth required pam_succeed_if.so user != root quiet_success
注释,保存。 - 打开文件
/root/.profile
将最后一行修改为:tty -s && mesg n || true
2、开启Ubuntu的ssh连接
【1】Ubuntu默认没有开启ssh的连接,所以使用xshell无法连接到虚拟机,下面开启。首先安装shh
apt-get install openssh-server
查看ssh是否启动:
ps -e|grep ssh
root@dk-machine:~# ps -e|grep ssh 3733 ? 00:00:00 sshdroot@dk-machine:~#
如果没有启动使用下面命令启动:
service ssh start
【2】ssh设置root远程登陆
gedit /etc/ssh/sshd_config
将第28行的内容注释掉
#PermitRootLogin prohibit-password
修改为:
PermitRootLogin yes
如下:
# Authentication:LoginGraceTime 120#PermitRootLogin prohibit-passwordPermitRootLogin yesStrictModes yes
接着重启电脑就可以使用Xshell连接了。
Connecting to 192.168.80.93:22...Connection established.To escape to local shell, press 'Ctrl+Alt+]'.Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.13.0-36-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage512 个可升级软件包。354 个安全更新。有新版本“18.04.2 LTS”可供使用运行“do-release-upgrade”来升级到新版本。Last login: Thu Aug 8 18:38:24 2019 from 192.168.80.1root@dk-machine:~#
3、修改Ubuntu的apt-get源为国内镜像源
【1】原文件备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
【2】编辑源列表文件
sudo vim /etc/apt/sources.list
【3】将原来的列表删除,添加如下内容(中科大镜像源)
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiversedeb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiversedeb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiversedeb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiversedeb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiversedeb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiversedeb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiversedeb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiversedeb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiversedeb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
【4】运行sudo apt-get update
步骤如下:
root@dk-machine:~# cd /etc/aptroot@dk-machine:/etc/apt# lsapt.conf.d sources.list sources.list.d trusted.gpg.dpreferences.d sources.list.bak trusted.gpgroot@dk-machine:/etc/apt# cp /etc/apt/sources.list /etc/apt/sources.list.bakroot@dk-machine:/etc/apt# gedit /etc/apt/sources.listroot@dk-machine:/etc/apt# sudo apt-get update获取:1 http://mirrors.ustc.edu.cn/ubuntu xenial InRelease [247 kB]获取:2 http://mirrors.ustc.edu.cn/ubuntu xenial-security InRelease [109 kB]获取:3 http://mirrors.ustc.edu.cn/ubuntu xenial-updates InRelease [109 kB]获取:4 http://mirrors.ustc.edu.cn/ubuntu xenial-proposed InRelease [260 kB]获取:5 http://mirrors.ustc.edu.cn/ubuntu xenial-backports InRelease [107 kB]获取:6 http://mirrors.ustc.edu.cn/ubuntu xenial/main Sources [868 kB]获取:7 http://mirrors.ustc.edu.cn/ubuntu xenial/restricted Sources [4,808 B]