How to fix the X11 verification information lost during SU (xsudo bash)

Source: Internet
Author: User

If you are a sudoer but do not know the root password, you may encounter the following similar information when running some X programs that require special permissions:

[Pc01]> sudo ethereal
Ssh (28492) X11 connection rejected because of wrong authentication.
The application 'ethereal' lost its connection to the display localhost: 11.0;
Most likely the X server was shut down or you killed/destroyed
The application.
[Pc01]> sudo su
[Pc01]> whoami
Root
[Pc01]> ethereal
Ssh (28492) X11 connection rejected because of wrong authentication.
The application 'ethereal' lost its connection to the display localhost: 11.0;
Most likely the X server was shut down or you killed/destroyed
The application.

This issue is especially prominent when you need to log on to a remote machine (of course, ssh must support X11 forward ).

The cause of this error is that the X11 authentication mechanism is completed through cookies, and these cookies are only applied to one user by default. Therefore, after su or sudo is used to change the euid, the original X11 authentication information is invalid and thus the program cannot be run.

To avoid this problem, you can use the following methods.

[Pc01]> echo $ DISPLAY
Localhost: 10.0
[Pc01]> xauth list | grep: 10
Pc01.xx./unix: 10 MIT-MAGIC-COOKIE-1 limit 66d9259e65500229ff48344df0371
[Pc01]> sudo su-
[Root @ pc01 ~] # Xauth add pc01.xx./unix: 10 MIT-MAGIC-COOKIE-1 limit 66d9259e65500229ff48344df0371
[Root @ pc01 ~] # Ethereal

This method transfers the original X11 verification information to new users and establishes a new connection with Xserver. This solves the problem of X11 verification information loss during the su process.

To simplify this process, you can write a script to automatically implement this function, which may be called xsudo:

#! /Bin/bash
#
# Xsudo...
#

Usage ()
...{
Echo "xsudo to forward X11 authentication when sudo, almost the same
Sudo"
}

If [$ #-lt 1]; then
Usage
Exit 0
Fi

Host = $ HOST
Display = $ DISPLAY
Port = 'echo $ DISPLAY | cut-d:-f 2 | cut-d.-f 1'

Key = 'xauth list | grep $ host | grep ": $ port" | grep unix'
Sudo su-c "xauth add $ key & $ *"

After adding xsudo to path, you can easily add sudo: D

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.