0

I'm installing and configuring the ssh in CentOs 8 with a virtual box machine.

I installed both libraries with following command:

sudo yum install openssh-server openssh-clients

Then I started the service with:

sudo systemctl enable sshd
sudo systemctl start sshd
sudo systemctl status sshd

And it's running normally.

When I try to edit the sshd_config file with the command:

sudo gedit /etc/ssh/sshd_config

I get the following error:

No protocol specified
Unable to init server: Could not connect: Connection refused

(gedit:5680): Gtk-WARNING **: 21:59:00.071: cannot open display: :0

Could someone help me, please?

8
  • 1
    You're likely running Xwindows under your account, but are trying to open the gedit session as root with the sudo command. Try xhost +127.0.0.1 to allow any user from the local host to access the display, then try the command again.
    – Fubar
    May 5, 2020 at 1:29
  • 1
    Welcome! It looks to me like you are not allowed to connect to the display because you use sudo. You can test whether using sudo gedit for other files in /etc also gets you this effect. If that's the case, the problem might be related to your display manager, wayland? with xorg it might work.
    – ingli
    May 5, 2020 at 1:29
  • When I ran sudo gedit /etc/sudoers I got the same error. May 5, 2020 at 1:32
  • Tried xhost +127.0.0.1 with no success. May 5, 2020 at 1:34
  • 1
    try xhost local: instead
    – Fubar
    May 5, 2020 at 1:40

3 Answers 3

2

Please try to added switch -E after sudo command:

sudo -E gedit /etc/ssh/sshd_config
1

You're likely running Xwindows under your account, but are trying to open the gedit session as root with the sudo command. Try xhost local: to allow any user from the local host to access the display, then try the command again. If that works, you can refine it more to just allow root to access the display with xhost +SI:localuser:root

0

instead of opening gedit from the shell, I suggest you use a terminal editor, like vi.

sudo vi /path/to/file
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .