Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Control 2 computers with one mouse and one keyboard

  1. #1
    Join Date
    Jun 2005
    Location
    New Jersey, United States
    Beans
    169
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Control 2 computers with one mouse and one keyboard

    What this guide will help you do:
    This guide will help you control two separate computers with one mouse and one keyboard, utilizing SSH and a little known tool called x2x.

    What this guide will not help you do:
    This guide will not help you set up a dual monitor system (One computer with two monitors.)

    Advantages of this method over a dual monitor:
    As said before, you will be controlling two separate computers. This means that both computers can be running completely different OS's, WM's, etc. This also means that you will have the combined hard drive space of both boxes.

    Disadvantages of this method:
    The only real downside to this is the fact that you can't drag anything from one screen to the other. (Of course there are other methods of transferring files, and I'm sure it is quite possible to set up a script that can be added to the nautilus right click menu for transferring files to the other box. However, this is beyond the scope of this guide.) If you are looking for simply a bigger desktop, with the capability to drag windows and such, then this is not for you, and you should look into a dual-monitor setup.

    With all that out of the way, let me explain how this works. Basically, you establish an SSH session with the computer you wish to control with the mouse/keyboard connected to your main box. Once connected, you run a program called x2x, which allows the cursor to "jump" to the second box when you move the mouse to the edge of the first screen, and vice-versa. Theoretically, this link could continue through infinite computers, meaning you can control three, four, five computers with one mouse. (Why you would have five computers on one desk is beyond me, although I wouldn't mind =])

    Okay, down to the nitty gritty.

    The first thing we need is all required packages. Plunk this in a terminal;

    Code:
    sudo apt-get install openssh-server x2x
    Now we need to set up a trusted pairing of the two computers, to avoid inputting a password every time you initiate the connection.

    Edit: These packages must be on both boxes. (Not so much x2x, but it's good to have it on both. openssh-server is a must on both.)

    Code:
    ssh-keygen -t rsa
    Press enter to accept the default file location, and then press enter twice for a null passphrase. You should now have the file "id_rsa.pub" in ~/.ssh. We need to copy this to the other computer as ~/.ssh/authorized_keys. To do this, put the following in the terminal:

    Code:
    scp ~/.ssh/id_rsa.pub user@host:/home/user/.ssh/authorized_keys
    Of course, substitute "user" with your username on the second box (unless it is the same as it is on the local machine, in that case you can just start with the host), and substitute the IP address of the remote box for "host."

    Okay! Now you should be able to SSH into the remote box without a password. To test it, just run the following:

    Code:
    ssh host
    And it should connect without any prompts.

    Everything good so far? Good. The hard parts done. Save the following two scripts in /bin:

    Name the following script "startxshare".

    Code:
    #!/bin/sh
    ssh -X host x2x -east -to :0 &
    (This is assuming that the second computer is to the right of your first. If it is not, simply change east to west.)

    Name the following script "stopxshare".

    Code:
    #!/bin/sh
    pid=$(ps aux | grep "ssh -X host" | grep S | awk {' print $2 '})
    kill -9 $pid
    Naturally, you will probably want to set up a static IP on at least the second machine, if not both. If it's dynamic, then the scripts will have to be changed whenever your IP changes, rendering the script useless. (Unless of course, you write a script to automatically update the X scripts, and that, although possible, can get tricky.)

    Also, it should go without saying, but I'll say it anyway, set both scripts to executable:

    Code:
    sudo chmod +x /bin/startxshare
    sudo chmod +x /bin/stopxshare
    Finally, you want to make sure that X Forwarding is enabled. It should be by default, but cant be two careful.

    Code:
    cat /etc/ssh/sshd_config | grep Forwarding
    If you see "X11Forwarding yes," you're ready to go. If not, do change it.

    Ready for the magic? Hit alt+f2, or open a terminal, and enter "startxshare." Now move your cursor to the desired screen edge, and all should go well. To stop it, just enter "stopxshare."

    Any questions? Ask away!

    -Gotti
    Last edited by jr.gotti; November 26th, 2007 at 07:44 PM.
    Good at writing shell scripts? Know anything about GTK programming?
    Help out a new project at http://www.s-online.org/labels/About.html

  2. #2
    Join Date
    Jul 2006
    Location
    Portland, OR
    Beans
    318
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Control 2 computers with one mouse and one keyboard

    I use Synergy, but x2x would seem to be more secure if its via ssh.

    I'll have to give it a try.


    ___
    EDIT: after a quick look on the synergy webpage, I found out that it will also work with OpenSSH. So if anyone wants an alternative to x2x. Synergy is FOSS and stable. http://synergy2.sourceforge.net/
    Last edited by kd7swh; November 25th, 2007 at 08:20 AM.

  3. #3
    Join Date
    Sep 2007
    Location
    UK
    Beans
    93
    Distro
    Kubuntu 8.04 Hardy Heron

    Re: Control 2 computers with one mouse and one keyboard

    Thanks!
    I've been looking for ways to do something similar... with a bit of messing, this might just do the job

    Just one thing... I would get rid of the little joke at the top... some people won't find it funny... particularly previous victims with empty hard drives, and the mods who are trying to stop this kinda thing.
    It would be a shame for you to get banned, since you're intent obviously isn't malicious. Just my advice
    ~ Dreaming dreams no mortal ever dared to dream before ~
    Bloggage

  4. #4
    Join Date
    Jun 2005
    Location
    New Jersey, United States
    Beans
    169
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Control 2 computers with one mouse and one keyboard

    Quote Originally Posted by Capricori View Post
    Thanks!
    I've been looking for ways to do something similar... with a bit of messing, this might just do the job

    Just one thing... I would get rid of the little joke at the top... some people won't find it funny... particularly previous victims with empty hard drives, and the mods who are trying to stop this kinda thing.
    It would be a shame for you to get banned, since you're intent obviously isn't malicious. Just my advice
    Eh, you're probably right...I took your advice. Oh, and I'm a victim of a similar joke. Ever see the fork bomb? It's almost impossible to resist!
    Good at writing shell scripts? Know anything about GTK programming?
    Help out a new project at http://www.s-online.org/labels/About.html

  5. #5
    Join Date
    Oct 2007
    Beans
    47

    Re: Control 2 computers with one mouse and one keyboard

    I've been trying to connect to the remote host by typing ssh host, but every time it comes back with Permission Denied. What do I need to do?

  6. #6
    Join Date
    Oct 2007
    Beans
    47

    Re: Control 2 computers with one mouse and one keyboard

    I'm also having difficult creating the startxshare and stopxshare files in /bin. It keeps telling me that I don't have permission. I understand what it's saying, I'm just not sure how I need to go about saving the files in a way that allows me to do it as the owner. I know, I'm a newb. But please explain how I need to save those files.

  7. #7
    Join Date
    Jun 2005
    Location
    New Jersey, United States
    Beans
    169
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Control 2 computers with one mouse and one keyboard

    Quote Originally Posted by gluonman View Post
    I've been trying to connect to the remote host by typing ssh host, but every time it comes back with Permission Denied. What do I need to do?
    You need to replace host with the IP address of your remote machine. Alternatively, you can edit /etc/hosts and add it in there. For example, I would either connect by typing:

    Code:
    ssh 192.168.2.20
    Or by adding the following line to /etc/hosts:

    Code:
    192.168.2.20 senior
    And connecting by typing:

    Code:
    ssh senior
    Hope this clears up some confusion!
    Good at writing shell scripts? Know anything about GTK programming?
    Help out a new project at http://www.s-online.org/labels/About.html

  8. #8
    Join Date
    Jun 2005
    Location
    New Jersey, United States
    Beans
    169
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Control 2 computers with one mouse and one keyboard

    Quote Originally Posted by gluonman View Post
    I'm also having difficult creating the startxshare and stopxshare files in /bin. It keeps telling me that I don't have permission. I understand what it's saying, I'm just not sure how I need to go about saving the files in a way that allows me to do it as the owner. I know, I'm a newb. But please explain how I need to save those files.
    You're gonnah wannah save those somewhere in your home folder, and then move them to /bin like this:

    Code:
    sudo cp startxshare /bin
    sudo cp stopxshare /bin
    sudo chmod +x /bin/startxshare
    sudo chmod +x /bin/stopxshare
    Good at writing shell scripts? Know anything about GTK programming?
    Help out a new project at http://www.s-online.org/labels/About.html

  9. #9
    Join Date
    Sep 2007
    Location
    UK
    Beans
    93
    Distro
    Kubuntu 8.04 Hardy Heron

    Re: Control 2 computers with one mouse and one keyboard

    @gluonman - You could save them into your home directory (where you do have permission), and them copy them to /bin as root (root can do pretty much what it likes). If you save the files to /home/whatever-your-name-is/startxshare, then you can copy it by opening a terminal and typing 'sudo cp ~/startxshare /bin/' (without the quotes). Then do the same for stopxshare.
    Using sudo gives you system-wide access, and the potential to damage things if you do something daft... So if you don't understand the command I just gave you, I would encourage you to investigate what it does first

    Edit: beat me to it

    @jr.gotti - fork bomb? Can't say I have.. shall have to investigate
    ~ Dreaming dreams no mortal ever dared to dream before ~
    Bloggage

  10. #10
    Join Date
    Oct 2007
    Beans
    47

    Re: Control 2 computers with one mouse and one keyboard

    Okay. When I said that I entered ssh host, I knew I was supposed to substitute host with the IP address. I just chose not to reveal my IP address. And I figured out how to save the startxshare and stopxshare. Only problem now is that when I run startxshare, I move my mouse to the left edge of the screen. I certainly disappears from this computer, but I don't see it pop up in the second computer. Do both computers need to be connected to internet or something? Do both need to have ssh installed?
    I originally found this thread trying to find out how I can connect my desktop PC to the internet by connecting it to my laptop (which is connected to a neighbourhood wireless router) via ethernet cable.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •