Run an application (including graphical) on another PC as another user

Hello,

This is really useful, since through this tip we can manage another PC, or it will make life a little easier at certain times.

They know that if they connect by SSH de PC # 1 a PC # 2 for example, and they try to open a program like Firefox to run and display in PC # 2, or some music or video player, we do it like this:

user @ pc2: ~$ firefox

But, it returns the following error:

(firefox: 1704): Gtk-WARNING **: cannot open display:

Well, here you will see how to open the softwares that we want, solving this error with just one command.

As well (and in my opinion this is more interesting), suppose I am PC # 1, I access PC # 2 what is my girlfriend's PC with the user kzkggaara for example, then I wish her (user cc) you are shown a notification (like those that appear when we raise or lower the volume, etc) that says “Stop listening to Enrique Iglesias !!!”Hehe… we will see how to do it, without needing to know the password of your user (cc in this example).

To access by SSH with our user (kzkggaara in this example) to PC # 2 (with IP address = 192.168.151.209) we put something like this:

  • ssh kzkggaara@192.168.151.209

Now, once inside our user we want to run a video player for example, the one that is installed by default in Ubuntu is Totem, we will use this to explain.

If we simply put in the terminal "totem”Will give us the aforementioned error, since before executing the application we must put the following line:

  • export DISPLAY =: 0.0

Putting this, and the problem is solved hehe. (if an error appears, change "0.0" by "1.0“) So, the steps to execute totem are:

  1. export DISPLAY =: 0.0
  2. totem

And ready.

If then we want to close totem we simply put:

  • killall totem

Now, suppose we want to run a browser like FirefoxAs We will not have to write the first line again (export DISPLAY =: 0.0), we simply put:

  • firefox

And problem solved 😉

However, if they leave the session and re-enter via SSH to PC # 2, they will have to write the line referring to export.

Now ... the most interesting in my opinion:

Run applications on another user's desktop:

We are already connected by SSH to PC # 2, we accessed with the user kzkggaara and what we want is to show the user cc a notification (like those that appear when we raise or lower the volume, etc) that says “Stop listening to Enrique Iglesias !!!"

In order to send notifications manually, we must install a package called libnotify-bin, to install it we put in the terminal:

  • sudo apt-get install libnotify-bin

And ready. Now, we will create a very small script with the command:

  • sudotouch /opt/script.sh

We will edit it with:

  • sudo nano /opt/script.sh

And in it we will write the following:

export DISPLAY =: 0.0

notify-send "Stop listening to Enrique Iglesias !!!"

We save and go out with [Ctrl] + [X], and now we will give the script permissions to run:

  • sudo chmod + x /opt/script.sh

And now we only need to execute the script, but we will execute it as the user cc, since what we want is for that notification to appear to that specific user. We move to the directory that contains the script:

  • cd / opt /

And now we run it:

  • sudo -u cc ./script.sh

Done, this would be it.

This is fully customizable, they can show you a gedit that says "I hacked you on the PC“, Or whatever they want, it all depends on how much they know how to improvise.

Nothing, the tutorial ends here.

Any error that comes up, problem, doubt or question, complaint or suggestion, I would appreciate it if you communicate it, constructive criticism is always well received.

Greetings and ... I know this will be useful to someone ^ _ ^


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   air0 said

    I suppose that you complicate things too much at least from my point of view, to do the same that you explained in the first part simply when connecting to the ssh server we add the -X parameter and after authenticating simply typing the name of the application it will open without no mistake
    example

    ssh -X kzkggaara@192.168.151.209
    firefox

    and with this we avoid doing the export ...

    1.    KZKG ^ Gaara <° Linux said

      Hello and welcome to the site 😀
      The problem is that, what I want is to write in a terminal «firefox»(To give an example), and that this opens on that other PC, yes, but that it is also shown on your display / monitor, that is, what I run in the terminal that is shown to the other user on their PC making him understand or seem that the computer has "gone crazy" 🙂

      If I do ssh -X $ user @ $ ip and then I write «firefox»In that terminal, the application (firefox in this case) will open to me on my monitor / screen, and nothing will be shown on the monitor of that other computer (to which I connected remotely via SSH).

      At least this is what I could appreciate with -XIf I'm wrong, please clarify the doubt.
      Greetings and once again, welcome to our site 😉

  2.   air0 said

    Exactly that happens if what happens is that I understood that that was what was intended, but I see that it is not so good, at least it is a way to open applications remotely, although it does not serve to joke 🙂 and thanks for the welcome here we will walk.

    1.    KZKG ^ Gaara <° Linux said

      That is the problem hehehehe, it doesn't work for me to joke, but to work it does, because the processing and loading is assumed by that remote PC, while the application is shown on my display, good tip 😉

      Greetings and we read each other here 🙂

  3.   The brown said

    If I understand the procedure well, now how do I get the IP of machine 2 from my console? It can ?

    I don't know anything about networks, what a shame 🙁

    1.    KZKG ^ Gaara <° Linux said

      In the terminal put: ifconfig
      There you can see details of each network interface, that is, if you have LAN (cable network), Wifi, or some other.

      Where it says "inet", there you can know the IP 😀
      And don't worry, no one is born knowing hahaha, we all learn as we go.

      regards

  4.   semptrion said

    Thank you!!! that is exactly what I was looking for ...

  5.   David said

    And if I wanted to do it from the web using php, also showing an image from the web, without using the script you create, that is to say something like that, how could I achieve it ???
    $ image = »http://website.net/imagen.png»;
    $ message = »stop listening to Enrique Iglesias»;
    exec ("export display =: 0.0 | notify-send $ message -i $ image");

  6.   alexweb said

    hello very good advice!
    Regarding the ssh, it works if you export the display.
    At least I get that on the console.

    A saludo.-

  7.   lida said

    When configuring the sshd_config file, it is necessary to modify the x11Forwarding to be able to do what you are doing? that's my doubt

  8.   Ricardo Luis Ordaz Villalobos said

    Hi, I have a question, can it be the other way around? For example, if I am on PC1 without firefox, and my girlfriend is on PC2 with firefox, could I run firefox from PC2 and make the browser window appear on PC1 where the browser is not installed?