Tuesday, August 14, 2012

[ Level 2 ] Share terminal in Ubuntu

How to share terminal in Ubuntu terminal 1:
$ id
uid=1000(stanley) ...
$ sudo chmod u+s /usr/bin/screen
$ sudo chmod 755 /var/run/screen
$ screen -S screen-share
$ [ctrl + a] :multiuser on
$ [ctrl + a] :acladd joseph
terminal 2:
$ ssh joseph@localhost
$ screen -x stanley/screen-share
Ref:
http://blog.bodhizazen.net/linux/shared-ssh-sessions-update-for-jaunty-ubuntu-904/ http://www.pixelbeat.org/docs/screen/
#!/bin/bash -vx

showUsage() {
  cat <<EOF
Usage:
  $0 [session name] [multi user]
Ex.
  $0 session guest
HowTO connect from guest:
  \$ ssh guest@remote_host
  \$ guest> screen -x [session holder]/[session name]
  \$ guest> screen -x stanley/screen-share
EOF
}

main () {
  if [ $# -lt 2 ] 
  then
    showUsage
    exit 1
  else
    pgName="`basename $0 | cut -d. -f1`"
    session="$1"
    user="$2"
    cfFile="/tmp/$pgName.cnf"
    cat /dev/null > $cfFile
    echo "multiuser on" >> $cfFile
    echo "acladd $user" >> $cfFile
    screen -S $session -c $cfFile
  fi  
}

main $@

Wish this helps.

regards,
Stanley Huang