The centos Server and ubuntu host machine both has gedit installed. Root login to the server is blocked and only a user can login via SSH through rsa keys. When I log in to the server with -X supplied as parameter, I can use gedit like:gedit filename.txt &and the file opens in gedit for me to edit and save. But if I do Sudo to edit files then I get following error:sudo gedit filename.txt &[1] 11039[user@server ~]$ X11 connection rejected because of wrong authentication.** (gedit:11040): WARNING **: Could not open X displayX11 connection rejected because of wrong authentication.X11 connection rejected because of wrong authentication.X11 connection rejected because of wrong authentication.(gedit:11040): Gtk-WARNING **: cannot open display: localhost:10.0[1]+  Exit 1                  sudo gedit filename.txtHow can I use Gedit in such situation.
using Sudo wth Gedit fails from XForwarded server
x11;sudo;xforwarding
You can use the sudoedit command instead.EDITOR=gedit sudoedit filename.txtwhat this does is take a copy of the file, then runs the editor as you, then if it detects the file has changed copy the results back.In most cases has the same effect as sudo gedit filename.txt but it runs the editor unprivileged and so your X forwarding should still work.