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

8

1

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?

Tony Stark

Posted 2009-08-20T11:37:02.607

Reputation: 1 930

Answers

12

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.

Mr. Shiny and New 安宇

Posted 2009-08-20T11:37:02.607

Reputation: 1 112

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

3

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.

gbjbaanb

Posted 2009-08-20T11:37:02.607

Reputation: 1 292

1

  • Run this to install Gnome:

    yum groupinstall "X Window System" "GNOME Desktop Environment"

  • Run gnome-session to start GNOME desktop environment.

  • To have the it started on boot, change the runlevel in /etc/inittab to 5.

    id:5:initdefault:

If you want to log into the desktop environment from another machine, you'll need to investigate XDMCP, VNC or FreeNX options. Have a look at this article: Cooking with Linux - My Desktop Lies over the Ocean. Also, GNOME comes with a bundled VNC server - vino. Run vino-preferences to configure and use this.

user4358

Posted 2009-08-20T11:37:02.607

Reputation:

@nagul: i had gnome installed, hit $gnome-session and gnome popped up. BUT, it did the same thing that happens when i type $startkde: the desktop pops up, but anytime i double click a folder it doesn't open up in that display, but in another x window BEHIND the GUI desktop that i can't get to! – Tony Stark – 2009-08-20T14:00:31.003

Hmm .. not sure I understand that correctly. I'm guessing here that your problem could be with the window manager. Gnome is a desktop environment - it runs a window manager to actually manage the windows, typically Metacity (the default). In the GUI desktop, do the windows have borders and minimise/maximise/close buttons? – None – 2009-08-20T15:09:24.433

i think its the window manager as well. i heard mac has a special x11 window manager that conflicts with the window manager used for gnome-session/startkde. in both of those commands, the respective desktop fully appears (wall paper, folders, top bar, etc) but if i say click a folder, it won't show up on the desktop, but is actually opened by the OSX x11 window manager BEHIND the opened gnome/kde desktop. if i alt-tab to select my terminal where i started the gui, and hit ctr-c (the terminal is still hidden behind the gui btw) the gui dies but the folder i opened is still open in an x11 window – Tony Stark – 2009-08-20T18:47:24.487