没有X11的Linux实现远程键盘共享

How to share keyboard/mouse in Linux without X11 environment

笔记本连个招呼都不打说死就死了,于是着手配置树莓派作为我的网络中心/手边唯一的linux终端。嵌入式就不要装X了。有X的话Synergy是跨平台共享鼠标键盘神器,显然没有图形服务器它根本不知道把输入往哪送。所以没有X的方案要解决两个问题:

We need to accomplish two things:
A. Login as root on startup automatically.
B. Send K/M actions

A

本来觉得很邪门了但是果然是有妥妥的办法的..

1)  添加行

NO_PASSWORD_CONSOLE tty1

到 /etc/login.defs

2) 在 /etc/inittab 找到

1:2345:respawn:/sbin/mingetty tty1

改成

1:2345:respawn:/sbin/mingetty –autologin root tty1

对我就直接登录了非常hěn呀的root

B

开始想写个脚本直接从SSH发送指令给tty1,琢磨了好久,发现一个叫console-tools的包里有指令writevt可以发送指令到/dev/tty1的input buffer里,但是不知道怎么按回车..
echo command > /dev/tty1 也是一样不知道怎么按回车.. 感觉好像不是这么用的。不过可以唤醒屏幕。
(后记: 确实不是这么用的 只是能发送显示字符串 另外发送 echo -ne “\033[9;0]” >/dev/tty1 就可以取消terminal的自动黑屏 参见 http://www.winds.org/pub/grdl/ANSI.txt , 为什么会有这种ANSI代码)
顷刻,突然想到直接在.bashrc里登录运行某个共享的screen就好了,~/.bashrc 写入

if [ "$STY" = "" ]
#不想SSH也自动的话就
#if [ "$STY" = "" ] && [ `tty` = "/dev/pts/0" ]
then
    if ! screen -list | grep -q "asdf"
    then
        screen -dmS asdf
    fi
    screen -x asdf
fi

-x是可以容许多用户登录同一个屏幕,所有内容完全同步。然后就行了,重启本尊,再分身SSH进去,本尊的屏幕很近的话就把分身SSH窗口拉到角落里看不见的地方,只要窗口激活输入就同步到本尊上,再设个快捷键,tsing.

A

1)  Add

NO_PASSWORD_CONSOLE tty1

To /etc/login.defs

2) In /etc/inittab Search for

1:2345:respawn:/sbin/mingetty tty1

Change to

1:2345:respawn:/sbin/mingetty –autologin root tty1

You can choose a different user of course. I use the raspberry Pi at home so, security is for pussies.

B

Simply tell bash to mount a Screen upon login. Append to ~/.bashrc

if [ "$STY" = "" ]
#Or this if you don't want to be mounted as SSH client
#if [ "$STY" = "" ] && [ `tty` = "/dev/pts/0" ]
then
    if ! screen -list | grep -q "asdf"
    then
        screen -dmS asdf
    fi
    screen -x asdf
fi

-x tolerates multiple mounts on a single screen. Optionally add a shortcut to your SSH client. There you go, it’s working really well for me.

6 thoughts on “没有X11的Linux实现远程键盘共享

  1. Savaliya Oil Maker Machine

    Savaliya Oil Maker Machine for Home Usage. This Product is Easy to Use and it produces health oil for your family. There are also some other products of savaliya industry, like coconut oil maker machine, peanut oil maker machine, sesame oil maker machine.

    Reply
  2. shreeja healthcare

    Shreeja Health Care is leading manufacturer of Oil Maker Machine. Shreeja Oil Extraction Machine is able to extract oil from various seeds like peanuts, Coconut, Sesame, Soybean, macadamia nuts, walnuts, sunflower seeds, vegetable seeds flaxseed etc.

    Reply

Leave a Reply

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