{"id":759,"date":"2013-04-24T23:08:30","date_gmt":"2013-04-24T23:08:30","guid":{"rendered":"http:\/\/tech.avant.net\/q\/?p=759"},"modified":"2013-04-24T23:10:00","modified_gmt":"2013-04-24T23:10:00","slug":"multiuser-screen","status":"publish","type":"post","link":"https:\/\/tech.avant.net\/q\/multiuser-screen\/","title":{"rendered":"multiuser screen"},"content":{"rendered":"<p>Previously, I discussed using <a href=\"\/q\/2012\/01\/screen-and-screenrc\/\">GNU screen as a window manager<\/a>.<\/p>\n<p>I would like to access my screen session concurrently from multiple hosts (say, at work, at home, and even remotely on my phone). I would also like to define default screens specific to one host.<\/p>\n<p>Default screens can be configured easily in the .screenrc in your home directory. To keep things simple I use a shared screenrc file, available in this <a href=\"https:\/\/github.com\/timwarnock\/dotfiles\">github repo<\/a>, this is shared across multiple environments that often have different uses (between home and work computers). Host specific screenrc commands are defined in a special .screenrc_local, that is loaded from the main .screenrc as follows,<\/p>\n<pre>\r\nsource .screenrc_local\r\n<\/pre>\n<p>In order to load default screens each with a specific initial command, I use the &#8220;screen&#8221; and &#8220;stuff&#8221; commands in my .screenrc_local, for example,<\/p>\n<pre>\r\n## default screens\r\nscreen -t bash 0\r\n\r\nscreen -t cloud 1\r\nstuff \"cd cloud\/cloudsource\/trunk\/roles\/; pushd ..\/..\/branches\/staging\/roles; dirs -v^M\"\r\n\r\nscreen -t ecr\/ 2\r\nstuff \"cd \/mnt\/sartre-data\/ecr\/; ll^M\"\r\n\r\n## go back to the first screen\r\nselect 0\r\n<\/pre>\n<p><a href=\"http:\/\/tech.avant.net\/q\/wp-content\/uploads\/2013\/04\/Screen-shot-2013-04-23-at-12.32.44-PM.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/tech.avant.net\/q\/wp-content\/uploads\/2013\/04\/Screen-shot-2013-04-23-at-12.32.44-PM-300x248.png\" alt=\"Screen shot 2013-04-23 at 12.32.44 PM\" width=\"300\" height=\"248\" class=\"alignleft size-medium wp-image-760\" srcset=\"https:\/\/tech.avant.net\/q\/wp-content\/uploads\/2013\/04\/Screen-shot-2013-04-23-at-12.32.44-PM-300x248.png 300w, https:\/\/tech.avant.net\/q\/wp-content\/uploads\/2013\/04\/Screen-shot-2013-04-23-at-12.32.44-PM.png 833w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nWith this configuration any new session will have those initial screens.<\/p>\n<p>Whatever is in the &#8220;stuff&#8221; command will be typed automatically into the screen session. Add &#8220;^M&#8221; to send a hard return to execute the &#8220;stuff&#8221; command.<br \/>\n<br style=\"clear: both;\" \/><br \/>\nTo enable multiuser mode in new screen sessions, add the following in your .screenrc<\/p>\n<pre>\r\n# enable multiuser screen\r\nmultiuser on\r\n<\/pre>\n<p>To enable multiuser mode in an existing screen session, press Ctrl-A : and enter &#8220;multiuser on&#8221;, that is,<\/p>\n<pre>\r\n^A :multiuser on\r\n<\/pre>\n<p>A multiuser screen session can be joined by multiple connections concurrently. By default, only your user account can access the shared screen session. To join a multiuser session, use the following command from the shell,<\/p>\n<pre>\r\n$ screen -x sessionname\r\n<\/pre>\n<p><a href=\"http:\/\/tech.avant.net\/q\/wp-content\/uploads\/2013\/04\/photo.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/tech.avant.net\/q\/wp-content\/uploads\/2013\/04\/photo-200x300.png\" alt=\"photo\" width=\"200\" height=\"300\" class=\"alignright size-medium wp-image-761\" srcset=\"https:\/\/tech.avant.net\/q\/wp-content\/uploads\/2013\/04\/photo-200x300.png 200w, https:\/\/tech.avant.net\/q\/wp-content\/uploads\/2013\/04\/photo.png 640w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/><\/a>If you don&#8217;t enter a sessionname, the most recent session will be joined. If you use &#8220;-xR&#8221; a new session will be created if a multiuser session did not exist.<\/p>\n<p>With this approach I can seamlessly switch to another computer or device, even in mid command.<\/p>\n<p>Best of all, multiple connections can be active at the same time &#8212; so for example you can have the same screen session open at home and in the office, as well as on your phone (typing commands on your phone knowing they&#8217;re also showing on your home and work computer).<\/p>\n<p><br style=\"clear: both\" \/>If you would like to allow other users to join your screen session, you would use the following commands, either in .screenrc or interactively using &#8220;Ctrl-A :&#8221;<\/p>\n<pre>\r\nacladd username\r\n<\/pre>\n<p>The other user can access this shared session using the following command,<\/p>\n<pre>\r\n$ screen -x owner\/sessionname\r\n<\/pre>\n<p>Sharing a screen session with multiple users can get complicated; and because you&#8217;ll need to setuid root on the screen binary, it&#8217;s not a good security practice. However, within a trusted developer network on a shared host it&#8217;s a very good way to collaborate. If you do wish to allow multiple users to share a single screen session, you&#8217;ll need to run the following,<\/p>\n<pre>\r\n$ sudo chmod u+s `which screen`\r\n$ sudo chmod 755 \/var\/run\/screen\r\n<\/pre>\n<p>If you run into the following, &#8220;ERROR: Cannot open your terminal &#8216;\/dev\/pts\/1&#8217; &#8211; please check.&#8221; or something similar, this is likely because the current user did not login directly but instead performed a &#8220;su &#8211; username&#8221; and does not have access to the pts. An interesting hack I found <a href=\"http:\/\/www.noah.org\/wiki\/Screen_notes\">here<\/a> resolves this using the &#8220;script&#8221; command (which creates a new pts as the current user), that is,<\/p>\n<pre>\r\nscript \/dev\/null\r\nscreen -x owner\/sessionname\r\n<\/pre>\n<p>By default, all users will have full access to the shared session; able to type commands as the session owner. You can modify access by using &#8220;aclchg&#8221;, or remove access with &#8220;acldel&#8221;.<\/p>\n<p>The &#8220;aclchg&#8221; command can apply to an entire session or to a specific window, e.g.,<\/p>\n<pre>\r\n## read only for entire session\r\naclchg username -w \"#\"\r\n\r\n## full access to screen 0 only\r\naclchg username +rwx 0\r\n<\/pre>\n<p>As a simple shortcut, you can use aclchg to add a new user with specific (such as read-only) access.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previously, I discussed using GNU screen as a window manager. I would like to access my screen session concurrently from multiple hosts (say, at work, at home, and even remotely on my phone). I would also like to define default screens specific to one host. Default screens can be configured easily in the .screenrc in [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,14],"tags":[],"_links":{"self":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/759"}],"collection":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/comments?post=759"}],"version-history":[{"count":10,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/759\/revisions"}],"predecessor-version":[{"id":787,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/759\/revisions\/787"}],"wp:attachment":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/media?parent=759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/categories?post=759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/tags?post=759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}