首先下载xshell,新建连接后设置主机名字,在host里面填上ipv4或ipv6的地址,注意端口号要在主机的/etc/ssh/sshd_config
这个文件中查看,即vi sshd_config
,其中:
# What ports, IPs and protocols we listen for Port 31422
就是对应的端口号,这个文件里,还要将PermitRootLogin 的值改为yes,PermitEmptyPasswords设置为no,然后:wq保存文件,最后重启重启ssh服务:service ssh restart
,就可以在xshell里用root登录了。
坑:
无法修改root密码:使用命令
sudo passwd root
,输入新的密码后提示Authentication token manipulation error
原因:一般是密码文件的权限的问题,不过也有可能是根目录空间满。
鉴别:使用lsattr命令查看存放用户和密码的文件属性,发现有i选项: (i:不得任意更动文件或目录。)所以导致所有的用户都不能修改密码,因为没有权限允许。
root@iaas-2018-04-12-09-48-41:/home# lsattr /etc/passwd ----i--------e-- /etc/passwd root@iaas-2018-04-12-09-48-41:/home# lsattr /etc/shadow ----i--------e-- /etc/shadow
解决办法:用chattr命令将i权限撤销
root@iaas-2018-04-12-09-48-41:/home# chattr -i /etc/passwd root@iaas-2018-04-12-09-48-41:/home# chattr -i /etc/shadow
无法新建用户:使用命令
sudo adduser hust
时,提示:sudo: unable to resolve host iaas-2018-04-12-09-48-41 Adding user `hust' ... Adding new group `hust' (1001) ... groupadd: cannot open /etc/group adduser: `/usr/sbin/groupadd -g 1001 hust' returned error code 10. Exiting.
鉴别:
root@iaas-2018-04-12-09-48-41:/home# lsattr /etc/group ----i--------e-- /etc/group root@iaas-2018-04-12-09-48-41:/home# lsattr /etc/gshadow ----i--------e-- /etc/gshadow
解决办法:
root@iaas-2018-04-12-09-48-41:/home# chattr -i /etc/group root@iaas-2018-04-12-09-48-41:/home# chattr -i /etc/gshadow
新建用户之后,新用户不在sudoers file,需要把新用户添加到里面去
鉴别:
[sudo] password for hust: hust is not in the sudoers file. This incident will be reported.
解决办法:在root下运行
visudo
命令,在打开的配置文件中找到root ALL=(ALL) ALL,在下面添加一行hust ALL=(ALL) ALL
因为需要用到浏览器,所以有必要安装图形化界面,具体步骤:
sudo apt-get install xinit sudo apt-get install gdm sudo apt-get install ubuntu-desktop sudo apt install gnome-panel
但只有xshell不能显示图形化界面,需要安装VNC
Ubuntu上安装VNC Server:apt-get install vnc4server
使用命令vnc4server,会生成配置文件/root/.vnc/xstartup
,修改配置文件
注释掉x-window-manager&
,并在后面加上一行gnome-session &
注:原xstartup文件
#!/bin/sh # Uncomment the following two lines for normal desktop: unset SESSION_MANAGER exec /etc/X11/xinit/xinitrc [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources xsetroot -solid grey vncconfig -iconic & x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & #x-window-manager& gnome-session &
因为桌面只有鼠标和壁纸,没有其他,执行以下命令换个桌面
sudo apt-get install gnome-shell sudo apt-get install ubuntu-gnome-desktop sudo apt-get install unity-tweak-tool sudo apt-get install gnome-tweak-tool
现在有了桌面端了,图标浏览器什么的都有,但是只能在浏览器上显示,还要想想办法,让它能在VNC上显示,用VNC Viewer看到的虚拟机总是灰色屏幕,鼠标变成一个X
又装了几个东西sudo apt-get install xrdp vnc4server xbase-clients
,将xstartup替换为:
#!/bin/sh export XKL_XMODMAP_DISABLE=1 #unset SESSION_MANAGER #exec /etc/X11/xinit/xinitrc unset DBUS_SESSION_BUS_ADDRESS [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources xsetroot -solid grey vncconfig -iconic & x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & gnome-session & gnome-panel & gnmoe-settings-daemon & metacity & nautilus & gnome-terminal & xfwm4 &
现在可以在VNC上正常访问远程的Linux桌面了。