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

I'm trying to get my gui on my CentOS machine up, but I frankly don't know the linux commands and google hasn't had a clear answer.

I'm assuming ssh -X and startx are the same, but maybe not; ssh -X starts up fine. startx however throws an enormous error. Are they not the same?

Also, what is the command to start gnome in CentOS/or other linux/unix servers? What about kde? I tried startkde, and it starts, but i can't open folders or anything (the desktop basically doesn't work right)

edit: clearly, i just have no idea what i'm doing. I've done a LOT of googling so maybe it will make my problems clearly if I state what I know/I'm trying:

  1. ssh -X should be used to run 1-2 programs, and i have no idea how it works (it doesn't start an x server locally, does it? then what's the dif between startx and ssh -X?).

  2. startx should be used to run GUIs, and it works by starting an xserver on my local machine.

  3. startx should be used in runlevel 3. will startx throw errors if tried in runlevel5? that might be why i can't use startx since i'm currently in runlevel5.

  4. if i'm in runlevel five, i should use xdm followed by kdm/gdm (by the way, xdm and gdm do nothing on my CentOS 5.3, and kdm says something about how only root would want to use kdm. my server is currently in runlevel 5 though, and both gnome-session and startkde bring up the respective desktops, so those commands work too.

is this understanding and these steps correct?


Solution 1:

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.

Solution 2:

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.