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.
I am using a macbook to connect to the server. To clarify: ssh -X is for forwarding x packets, used for just opening 1-2 programs, and uses x on the local (client) machine. I'm afraid I didn't entirely understand why startx is different from ssh -X on a technical level; what's the difference between running an x server locally and forwarding the ports to have programs open in x locally? ...that i'm not using a server in the latter..? And in conclusion, if i want this gui thing to work, i need to research XDM/GDM/KDM (switch to level 5) or VNC? – Tony Stark – 2009-08-20T13:08:41.703
@mr. shiny and new: hmm, after googling, is the difference that in ssh -X you are connecting to the x server on the remove computer, whereas with ssh and startx i am creating a x server on my local machine? – Tony Stark – 2009-08-20T13:33:40.830
@hatorade: X programs (technically called clients) such as firefox require a display, technically called a server. startx starts the server, or display, locally on the physical video card. ssh -X tells the remote computer that you have a display on your local system, and instructs programs running remotely to use it. You always have an X server if you are displaying an X client program. – Mr. Shiny and New 安宇 – 2009-08-20T16:00:06.430
@mr. shiny and new: yeah as i explained a couple comments down, i don't think i'm connecting my x11 with the XDM; it looks like the mac handling of x11 windows individually kills the complete graphic desktop (for example, using gnome-panel works beautifully compared to gnome-session, because i just get the top programs panel and any app i open opens in a separate x11 which i can see and use since there is no desktop background/icons in my way) – Tony Stark – 2009-08-20T18:51:22.870
@hatorade: Yeah, XDM is one of the preferred approach for a full desktop, and ssh -X would be preferred for running individual apps. You could use a full-screen X11 window (see the link in the answer) and run a full desktop environment there. It might work over ssh -X. But the default mode for Apple's X11 is to manage the windows as if they are local apps and this does conflict with parts of the gnome or KDE desktop. – Mr. Shiny and New 安宇 – 2009-08-21T16:13:15.467