CentOS - difference between ssh -X and startx, and starting a gui

ssh -X is not the same as startx. SSH is a program used for connecting to another computer with a shell. X is the graphical display program.

SSH can be used as an interactive command shell and can also be used to forward ports. ssh -X forwards the local X display's port to the remote computer and usually sets up the remote environment so that if you start a graphical program remotely it will display locally. Normally you wouldn't run an entire desktop such as KDE in this way; you'd just run one or two programs.

startx is a command used to start an X server locally when you are logged into the console of the server, that is, the physical keyboard and screen. Most people avoid using startx because it can be a security risk if you leave your computer unattended. Starting X creates a second virtual console (the first was the text console you logged into), and someone can switch back to the text console (CTRL-ALT-F1 or something similar) and hit CTRL-C to kill your X console, and then they are logged-in as you in your text console. But if you don't leave the computer unattended it may be okay to use occaisionally.

The normal way to run a full-fledged graphical desktop on a system is to use a login manager such as XDM (or GDM/KDM for Gnome/KDE). On RedHat and friends this is usually achieved by switching to runlevel 5. From a command prompt you can type telinit 5 to switch temporarily, or edit /etc/inittab to set the default runlevel (typical choices are 3 - no X - and 5 - with X).

As for starting GNOME and KDE, by default when you run startx CentOS should run one of them (probably GNOME). There are configuration files you can change to override the default.

If you want to access a full desktop environment remotely, you need to look into setting XDM up for remote access, or using VNC or some other remote desktop protocol. For a full desktop I'd recommend something like VNC because that way your session stays open when you are disconnected. But you should consider that typical X or VNC over the network is not encrypted and you may want to set up an ssh port forwarding tunnel to encrypt the data. If you just run one or two apps with ssh -X then it will be encrypted already.

What kind of client computer are you using to connect to this server? Both ssh -X and XDM require a local X display, whereas something like VNC does not.

Edit: If you have an X server on your local computer, you can use ssh -X to connect to the CentOS machine and start a program, such as firefox, which will display on the macbook. This link has information about using X on MacOS X. By default Apple's X server shows each application in its own window, which is perfect for running a few apps using the ssh -X method. However, if you wanted to run an entire full-screen graphical environment, you'd need to have your local X server connect to the CentOS's XDM; you'll then see (on your macbook) a screen similar to what you'd see if you were logged into the CentOS's local console. This basically uses your Macbook as a dumb terminal: only the display, keyboard, and mouse are used locally. The programs execute on the CentOS machine. Unfortunately I can't help you set up a dumb terminal since it's been about 10 years since I last did it.

If you don't have an X server on your local computer, you can set up something like VNC (see here for more remote-desktop products), so that the X session is running on the server, on its physical display, but can be accessed remotely from a computer with the appropriate remote-desktop client. For example, KDE has a desktop-sharing application which exposes the running KDE session over VNC. You could log into the CentOS server (via XDM or text-console + startx), start the desktop-sharing, and then connect to that with a VNC client on the Macbook.


and to install KDE type:

yum groupinstall "X Window System" "KDE (K Desktop Environment)" 

If you've already got Gnome installed, it will be the default. Edit /etc/sysconfig/desktop to change this. Set:

DESKTOP="KDE"
DISPLAYMANAGER="KDE" 

or use switchdesk kde to flip to KDE.

Tags:

Gnome

Kde

Centos