Editing /etc/sysctl.conf with Gedit

I’m trying to edit /etc/sysctl.conf with Gedit to change swappiness and I get the following error:

xxxxxx@linux-2t4v:/> sudo gedit /etc/sysctl.conf
Unable to init server: Could not connect: Connection refused

(gedit:29752): Gtk-WARNING **: cannot open display: 
xxxxxx@linux-2t4v:/> 

Any help appreciated

Apparently gedit is a GUI program. Do not use sudo, but kdesu or gnomesu (depending on what you use) e.g. from Execute command or a terminal. Or stay in the CLI and use vi.

Or stay in the CLI and use nano.

I agree that more user friendly CLI editors then vi will exist. But as I never used them, I didn’t know their names. If the OP wants to edit from the CLI, nano is probably the better tool.:wink:

Thanks gentlemen,

I will try your suggestions; however I would ultimately prefer a gui text editor. BTW, I have always been able to edit system files in Ubuntu with gedit, 7+ years. I don’t know why I can’t do it in openSUSE. Is there any gui based text editor that will edit system files? I don’t want to make any mistakes with these.

Did you try kdesu or gnomesu as I advised? When you did and failed, we would like to see what happened. When you didn’t try, you should not ask why you can’t do it.

I use KDE and never had any problem in doing e.g.

kdesu kwrite /etc/hosts

Ubuntu applies a different security system.
Ubuntu doesn’t really support using “su” like we do here in openSUSE, and has a different “sudo” security policy in part to compensate.
I haven’t checked, but Ubuntu might looser security for sysctl.conf.
In general and not just because I use openSUSE, I feel the more traditional ways openSUSE applies security is clearer so less prone to mis-understanding and mistake.

You should also be able to launch any graphical app like gedit from a root console (created with “su”) which would then be able to edit files like sysctl.conf.
This would work in any openSUSE running any Desktop, or even IceWM which does not formally run a Desktop.

TSU

Thank you sir,

Good answer! This is a new build with many issues. I had a lot to do.

What I ultimately did was to cat sysctl.conf, copy it into gedit, edit the file, then sudo cp the file back into root… I am greatful for everyone’s help and I will investigate all the suggestions when my workload diminishes. You’re right Ubuntu doesn’t like su.

BTW, su complained a lot, but it let me do it:

xxxxxx@linux-2t4v:~> su
Password: 
linux-2t4v:/home/xxxxxx # gedit /etc/sysctl.conf

(gedit:17943): dconf-WARNING **: failed to commit changes to dconf: The connection is closed

(gedit:17943): dconf-WARNING **: failed to commit changes to dconf: The connection is closed
Error creating proxy: The connection is closed (g-io-error-quark, 18)
Error creating proxy: The connection is closed (g-io-error-quark, 18)
Error creating proxy: The connection is closed (g-io-error-quark, 18)
Error creating proxy: The connection is closed (g-io-error-quark, 18)
Error creating proxy: The connection is closed (g-io-error-quark, 18)

(gedit:17943): dconf-WARNING **: failed to commit changes to dconf: The connection is closed

(gedit:17943): dconf-WARNING **: failed to commit changes to dconf: The connection is closed

(gedit:17943): dconf-WARNING **: failed to commit changes to dconf: The connection is closed

** (gedit:17943): WARNING **: Set document metadata failed: Setting attribute metadata::gedit-position not supported

(gedit:17943): dconf-WARNING **: failed to commit changes to dconf: The connection is closed
linux-2t4v:/home/xxxxxx # 




[QUOTE=heidiheidi;2782051
BTW, su complained a lot, but it let me do it:

xxxxxx@linux-2t4v:~> su
Password: 
linux-2t4v:/home/xxxxxx # gedit /etc/sysctl.conf

(gedit:17943): dconf-WARNING **: failed to commit changes to dconf: The connection is closed

(gedit:17943): dconf-WARNING **: failed to commit changes to dconf: The connection is closed
Error creating proxy: The connection is closed (g-io-error-quark, 18)
...

[/QUOTE]

Apparently (from other posts) you are using Gnome.
If you had done:


gnomesu gedit /etc/sysctl.conf

as suggested by hcvv in post #2 you would have done your job with just a few irrelevant warnings.
You used “su” within the context of your “normal” user, hence the errors you see.
To open a session for user “root” you have to use:


su -
<root password>
gedit /etc/sysctl.conf

including the trailing dash, or “su --login” in the long form. See “man su” for further details.

[QUOTE=OrsoBruno;2782095]Apparently (from other posts) you are using Gnome.
If you had done:


gnomesu gedit /etc/sysctl.conf

as suggested by hcvv in post #2 you would have done your job with just a few irrelevant warnings.

Oops, now I get it. I was scanning post #2 way too fast. I’ve never used gnomesu before; I must have thought it was an editor.

Oh, snap.

It works pretty good too; although it does complain a little:

xxxxxx@linux-2t4v:~> gnomesu gedit /etc/sysctl.conf

(gnomesu:25465): GLib-GObject-WARNING **: The property GtkButton:use-stock is deprecated and shouldn’t be used anymore. It will be removed in a future version.

(gnomesu:25465): GLib-GObject-WARNING **: The property GtkSettings:gtk-button-images is deprecated and shouldn’t be used anymore. It will be removed in a future version.

(gnomesu:25465): Gtk-WARNING **: gtk_window_set_titlebar() called on a realized window
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

** (gedit:25472): WARNING **: Set document metadata failed: Setting attribute metadata::gedit-position not supported
xxxxxx@linux-2t4v:~>

And I repeated that in post #5. You realy should try to read ansers carfully. And answer them, even when you think they are not applicable. When people are trying to help you and feel as being ignored, in the end you may be the one that is ignored when you have any questions/problems in the future.:wink: