Recently I start to get "No protocol specified" when using sudo vim. It's just a warning I guess, because everything was working normally (I can open, edit and save files). The message doesn't appear if I use sudo -E vim so I think I did something wrong when editing /etc/profile recently, but I'm not sure. How can I fix this?

  • 1
    Not everything is working normally. Mouse support isn't working, it needs a protocol such as gpm or the xterm mouse protocol. – ninjalj Feb 26 '11 at 17:52

A recent upgrade changed default settings for sudo. If anyone have this problem check your sudoer configuration. From an example in the man page:

# Run X applications through sudo; HOME is used to find the
# .Xauthority file.  Note that other programs use HOME to find
# configuration files and this may lead to privilege escalation!
Defaults env_keep += "DISPLAY HOME"

Make sure you have something like that in /etc/sudoers (use visudo to edit the file if you need to).

EDIT: I don't know exactly since when, but at least xauth 1.0.9 supports the environment variable XAUTHORITY. Setting that and leaving HOME untouched, also fixes the protocol warning and is the better solution, as no world-writeable IPC resources (sockets/pipes) are created pointing to root resources (one avenue for privilege escalation). xauth doesn't automatically export the variable to the environment, so the best way is to set it in your shell's initialization.


According to this thread, there are two possible solutions to your problem:

Put the following line in my root users .bashrc script

export XAUTHORITY=/home/<user>/.Xauthority

then I copied .Xauthority to root also, i.e.

sudo cp ~/.Xauthority /root

and now the warning is gone.

You could also try running via gksudo.

Anyway, both are worth a try...

  • I copied .Xauthority to /root and that's it! – phunehehe Feb 27 '11 at 4:27
  • No I was wrong, after rebooting I got "invalid key" error. – phunehehe Feb 28 '11 at 9:07
  • 1
    As far as I remember the contents of a .Xauthority file changes, so you should symlink it instead of copying. – Adam Byrtek Mar 31 '11 at 21:43

Although the question already has some answers, none worked for me completely. I solved it through a combination of above few suggestions and some bits of mine for my Debian distro.

I made a symlink to .Xauthority file for root and all other users. The problem got resolved for root user, because root has access permissions to that file, but not for other users. I added read-only permission for all other users for .Xauthority file.

#do this for all other users who do not have .Xauthority file    
ln -s /home/userwithxauth/.Xauthority .Xauthority

#run the following command to give read only access permission to .Xauthority file
chmod 644 /home/userwithxauth/.Xauthority

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.