Archive:Getting Started/Run/Shell: Difference between revisions

From KDE TechBase
m (Text replace - "<code>" to "<syntaxhighlight lang="text">")
m (Reverted edits by KennethMartinez (talk) to last revision by AnneW)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:I18n/Language Navigation Bar|Getting_Started/Run/Shell}}
__NOINDEX__
 
== Using the normal shell with sux ==
== Using the normal shell with sux ==


For this method, the tool '''sux''' (http://fgouget.free.fr/sux/sux-readme.shtml) is required. '''sux''' is available on most distributions. Otherwise you could rely on the ''normal shell without sux'' method below. '''sux''' allows you to change to another user with an implicit managing of the X forwarding details (authentication and DISPLAY exporting) in a clean and simple way.
For this method, the tool '''sux''' (http://fgouget.free.fr/sux/sux-readme.shtml) is required. '''sux''' is available on most distributions. Otherwise you could rely on the ''normal shell without sux'' method below. '''sux''' allows you to change to another user with an implicit managing of the X forwarding details (authentication and DISPLAY exporting) in a clean and simple way.


To login, type <syntaxhighlight lang="bash">sux - kde-devel</code>
To login, type <syntaxhighlight lang="bash">sux - kde-devel</syntaxhighlight>


All environment variables and everything else should be set up correctly by your {{path|[[Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/.bashrc|.bashrc]]}}. To start an application, simply type it's name; for example <syntaxhighlight lang="bash">kwrite</code>
All environment variables and everything else should be set up correctly by your {{path|[[Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/.bashrc|.bashrc]]}}. To start an application, simply type it's name; for example <syntaxhighlight lang="bash">kwrite</syntaxhighlight>
{{Note|If you get errors about missing mimetypes or such, try running the following:<syntaxhighlight lang="bash">unset XDG_DATA_DIRS ; kbuildsycoca4</code>
{{Note|If you get errors about missing mimetypes or such, try running the following:<syntaxhighlight lang="bash">unset XDG_DATA_DIRS ; kbuildsycoca4</syntaxhighlight>
}}
}}


== Using the normal shell without sux ==
== Using the normal shell without sux ==
The simplest method to launch KDE 4 applications is using <tt>su</tt> to login as the <tt>kde-devel</tt> user and then simply start any KDE 4 application from command line. To login, type
The simplest method to launch KDE 4 applications is using <tt>su</tt> to login as the <tt>kde-devel</tt> user and then simply start any KDE 4 application from command line. To login, type
<syntaxhighlight lang="bash">su - kde-devel</code>
<syntaxhighlight lang="bash">su - kde-devel</syntaxhighlight>
and then, after entering your password
and then, after entering your password
<syntaxhighlight lang="bash">export DISPLAY=:0</code>
<syntaxhighlight lang="bash">export DISPLAY=:0</syntaxhighlight>
{{Note|Exporting the <tt>DISPLAY</tt> variable is necessary so that the KDE 4 applications appear on your normal KDE 3 desktop.}}
{{Note|Exporting the <tt>DISPLAY</tt> variable is necessary so that the KDE 4 applications appear on your normal KDE 3 desktop.}}
All environment variables and everything else should be set up correctly by your {{path|[[Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/.bashrc|.bashrc]]}}. To start an application, simply type it's name; for example <syntaxhighlight lang="bash">kwrite</code>
All environment variables and everything else should be set up correctly by your {{path|[[Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/.bashrc|.bashrc]]}}. To start an application, simply type it's name; for example <syntaxhighlight lang="bash">kwrite</syntaxhighlight>
{{Note|
{{Note|
If you get errors about missing mimetypes or such, try the following:
If you get errors about missing mimetypes or such, try the following:
* run <syntaxhighlight lang="bash">unset XDG_DATA_DIRS ; kbuildsycoca4</code>
* run <syntaxhighlight lang="bash">unset XDG_DATA_DIRS ; kbuildsycoca4</syntaxhighlight>
}}
}}
{{Note|
{{Note|
If you get an error about not being able to connect to an X server, be sure to issue
If you get an error about not being able to connect to an X server, be sure to issue
<syntaxhighlight lang="bash">sudo xhost +local:kde-devel</code>
<syntaxhighlight lang="bash">sudo xhost +local:kde-devel</syntaxhighlight>
as your regular KDE 3 user to ensure that the application can connect to your current X session.
as your regular KDE 3 user to ensure that the application can connect to your current X session.


Although your X server should accept incoming TCP connections, this is often switched off as a distribution default (like with Kubuntu Feisty). When using <tt>kdm</tt> you must edit <tt>/etc/kde3/kdm/kdmrc</tt> as root and make sure it does not contain:
Although your X server should accept incoming TCP connections, this is often switched off as a distribution default (like with Kubuntu Feisty). When using <tt>kdm</tt> you must edit <tt>/etc/kde3/kdm/kdmrc</tt> as root and make sure it does not contain:
<syntaxhighlight lang="text">ServerArgsLocal=-nolisten tcp</code>
<syntaxhighlight lang="text">ServerArgsLocal=-nolisten tcp</syntaxhighlight>
Once you have fixed this, you will need to restart your X server. The <tt>xhost</tt> command should no longer return an "unable to open display" error.
Once you have fixed this, you will need to restart your X server. The <tt>xhost</tt> command should no longer return an "unable to open display" error.


Line 35: Line 34:
#! /bin/sh
#! /bin/sh
xhost +local:kde-devel
xhost +local:kde-devel
</code>
</syntaxhighlight>
Make sure that the new file is executable by using <tt>chmod +x</tt> on it.
Make sure that the new file is executable by using <tt>chmod +x</tt> on it.


Line 44: Line 43:


The simplest way to run a KDE 4 application with SSH in your current desktop environment is to get an X-aware shell prompt as the <tt>kde-devel</tt> user like this:
The simplest way to run a KDE 4 application with SSH in your current desktop environment is to get an X-aware shell prompt as the <tt>kde-devel</tt> user like this:
<syntaxhighlight lang="bash">ssh -X kde-devel@localhost</code>
<syntaxhighlight lang="bash">ssh -X kde-devel@localhost</syntaxhighlight>
Now you can launch KDE apps as usual, for example:
Now you can launch KDE apps as usual, for example:
<syntaxhighlight lang="bash">kwrite</code>
<syntaxhighlight lang="bash">kwrite</syntaxhighlight>
The two lines can be conveniently combined:
The two lines can be conveniently combined:
<syntaxhighlight lang="bash">ssh -X kde-devel@localhost kwrite</code>
<syntaxhighlight lang="bash">ssh -X kde-devel@localhost kwrite</syntaxhighlight>


{{Note|
{{Note|
Line 57: Line 56:
=== Passwordless login ===
=== Passwordless login ===
Before anything serious can be done using this method, a passwordless login needs to be set up. To start, run the following command as the regular desktop user:
Before anything serious can be done using this method, a passwordless login needs to be set up. To start, run the following command as the regular desktop user:
<syntaxhighlight lang="bash">ssh-keygen -t rsa</code>
<syntaxhighlight lang="bash">ssh-keygen -t rsa</syntaxhighlight>
Hit enter three times to accept the path of {{path|~/.ssh/id_rsa}} and an empty passphrase. Now, copy the single line in {{path|~/.ssh/id_rsa.pub}} that's printed after running this command:
Hit enter three times to accept the path of {{path|~/.ssh/id_rsa}} and an empty passphrase. Now, copy the single line in {{path|~/.ssh/id_rsa.pub}} that's printed after running this command:
<syntaxhighlight lang="bash">cat ~/.ssh/id_rsa.pub</code>
<syntaxhighlight lang="bash">cat ~/.ssh/id_rsa.pub</syntaxhighlight>
After that line is copied, <tt>ssh</tt> back into the <tt>kde-devel</tt> user and put the copied line in the file {{path|$HOME/.ssh/authorized_keys}}:
After that line is copied, <tt>ssh</tt> back into the <tt>kde-devel</tt> user and put the copied line in the file {{path|$HOME/.ssh/authorized_keys}}:
<syntaxhighlight lang="bash">ssh -X kde-devel@localhost $HOME/kde/bin/kwrite \
<syntaxhighlight lang="bash">ssh -X kde-devel@localhost $HOME/kde/bin/kwrite \
   $HOME/.ssh/authorized_keys</code>
   $HOME/.ssh/authorized_keys</syntaxhighlight>
Paste in the line, save the file, and quit KWrite.
Paste in the line, save the file, and quit KWrite.


Next make sure {{path|$HOME/.ssh/authorized_keys}} has the correct permissions:
Next make sure {{path|$HOME/.ssh/authorized_keys}} has the correct permissions:
<syntaxhighlight lang="bash">ssh kde-devel@localhost chmod og-xrw ~kde-devel/.ssh/authorized_keys</code>
<syntaxhighlight lang="bash">ssh kde-devel@localhost chmod og-xrw ~kde-devel/.ssh/authorized_keys</syntaxhighlight>
Now try running KWrite again with the same SSH command; you shouldn't have to enter a password anymore:
Now try running KWrite again with the same SSH command; you shouldn't have to enter a password anymore:
<syntaxhighlight lang="bash">ssh -X kde-devel@localhost $HOME/kde/bin/kwrite</code>
<syntaxhighlight lang="bash">ssh -X kde-devel@localhost $HOME/kde/bin/kwrite</syntaxhighlight>


{{warning|Using a passwordless SSH login has certain '''security risks''', so make sure you protect your <tt>~/.ssh/id_rsa</tt> file by restricting access to it with  
{{warning|Using a passwordless SSH login has certain '''security risks''', so make sure you protect your <tt>~/.ssh/id_rsa</tt> file by restricting access to it with  
<syntaxhighlight lang="bash">chmod og-xrw ~/.ssh/id_rsa</code>(although the file should have these permissions when it is created)}}
<syntaxhighlight lang="bash">chmod og-xrw ~/.ssh/id_rsa</syntaxhighlight>(although the file should have these permissions when it is created)}}


=== The SSH desktop file ===
=== The SSH desktop file ===
Line 80: Line 79:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
ssh -X kde-devel@localhost $HOME/kde/bin/
ssh -X kde-devel@localhost $HOME/kde/bin/
</code>
</syntaxhighlight>


A simple .desktop file that runs KWrite would have the following contents:
A simple .desktop file that runs KWrite would have the following contents:
Line 106: Line 105:
X-KDE-SubstituteUID=false
X-KDE-SubstituteUID=false
X-KDE-Username=
X-KDE-Username=
</code>
</syntaxhighlight>


{{tip|Apps launched using SSH like this don't trigger the correct launch responses, so you probably want to disable "launch feedback" for your .desktop files}}
{{tip|Apps launched using SSH like this don't trigger the correct launch responses, so you probably want to disable "launch feedback" for your .desktop files}}

Latest revision as of 15:55, 31 July 2012

Using the normal shell with sux

For this method, the tool sux (http://fgouget.free.fr/sux/sux-readme.shtml) is required. sux is available on most distributions. Otherwise you could rely on the normal shell without sux method below. sux allows you to change to another user with an implicit managing of the X forwarding details (authentication and DISPLAY exporting) in a clean and simple way.

To login, type

sux - kde-devel

All environment variables and everything else should be set up correctly by your .bashrc. To start an application, simply type it's name; for example

kwrite
Note
If you get errors about missing mimetypes or such, try running the following:
unset XDG_DATA_DIRS ; kbuildsycoca4


Using the normal shell without sux

The simplest method to launch KDE 4 applications is using su to login as the kde-devel user and then simply start any KDE 4 application from command line. To login, type

su - kde-devel

and then, after entering your password

export DISPLAY=:0
Note
Exporting the DISPLAY variable is necessary so that the KDE 4 applications appear on your normal KDE 3 desktop.

All environment variables and everything else should be set up correctly by your .bashrc. To start an application, simply type it's name; for example

kwrite
Note
If you get errors about missing mimetypes or such, try the following:
  • run
    unset XDG_DATA_DIRS ; kbuildsycoca4
    
Note
If you get an error about not being able to connect to an X server, be sure to issue
sudo xhost +local:kde-devel

as your regular KDE 3 user to ensure that the application can connect to your current X session.

Although your X server should accept incoming TCP connections, this is often switched off as a distribution default (like with Kubuntu Feisty). When using kdm you must edit /etc/kde3/kdm/kdmrc as root and make sure it does not contain:

ServerArgsLocal=-nolisten tcp

Once you have fixed this, you will need to restart your X server. The xhost command should no longer return an "unable to open display" error.

For convenience, you should put this in the Autostart of your regular user. To do this, create a new file in the $HOME/.kde/Autostart directory of your regular user with the following content:

#! /bin/sh
xhost +local:kde-devel

Make sure that the new file is executable by using chmod +x on it.

If you'd like to find out more about the security issues involved with using xhost, see this article


Using SSH

The simplest way to run a KDE 4 application with SSH in your current desktop environment is to get an X-aware shell prompt as the kde-devel user like this:

ssh -X kde-devel@localhost

Now you can launch KDE apps as usual, for example:

kwrite

The two lines can be conveniently combined:

ssh -X kde-devel@localhost kwrite
Note
If this gives you any errors, try the troubleshooting tips from the section above. If you receive something like "kwrite: cannot connect to X server", open /etc/ssh/sshd_config and enable the "X11Forwarding" key. Restart sshd and it should work fine.


Passwordless login

Before anything serious can be done using this method, a passwordless login needs to be set up. To start, run the following command as the regular desktop user:

ssh-keygen -t rsa

Hit enter three times to accept the path of ~/.ssh/id_rsa and an empty passphrase. Now, copy the single line in ~/.ssh/id_rsa.pub that's printed after running this command:

cat ~/.ssh/id_rsa.pub

After that line is copied, ssh back into the kde-devel user and put the copied line in the file $HOME/.ssh/authorized_keys:

ssh -X kde-devel@localhost $HOME/kde/bin/kwrite \
  $HOME/.ssh/authorized_keys

Paste in the line, save the file, and quit KWrite.

Next make sure $HOME/.ssh/authorized_keys has the correct permissions:

ssh kde-devel@localhost chmod og-xrw ~kde-devel/.ssh/authorized_keys

Now try running KWrite again with the same SSH command; you shouldn't have to enter a password anymore:

ssh -X kde-devel@localhost $HOME/kde/bin/kwrite
Warning
Using a passwordless SSH login has certain security risks, so make sure you protect your ~/.ssh/id_rsa file by restricting access to it with
chmod og-xrw ~/.ssh/id_rsa
(although the file should have these permissions when it is created)


The SSH desktop file

If you want to be able to launch apps more easily than running them with an SSH command from the command line, one way is to create .desktop files that ssh into the other account.

Note
This will only be useful if your desktop environment supports .desktop files, but at least KDE and GNOME do.


You can start with an existing .desktop file as a template (like one from your desktop) or you can make one from scratch. The main idea is to prefix the command being run with this string:

ssh -X kde-devel@localhost $HOME/kde/bin/

A simple .desktop file that runs KWrite would have the following contents:

[Desktop Entry]
Categories=Qt;KDE;TextEditor;
Comment=
DocPath=kwrite/index.html
Encoding=UTF-8
Exec=ssh -X kde-devel@localhost /home/kde-devel/kde/bin/kwrite %U
GenericName=Text Editor
Icon=kwrite
InitialPreference=8
MimeType=text/plain
Name=KWrite (kde-devel)
Path=
StartupNotify=false
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-StartupType=Multi
X-DCOP-ServiceType=non
X-KDE-StartupNotify=true
X-KDE-SubstituteUID=false
X-KDE-Username=
Tip
Apps launched using SSH like this don't trigger the correct launch responses, so you probably want to disable "launch feedback" for your .desktop files


Note
In order to create a .desktop file for a KDE 4 app by using this pattern, the app's package will have to have been installed into ~/kde/bin using the cmakekde command