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 ^ _ ^