{"id":1333,"date":"2018-12-17T06:39:00","date_gmt":"2018-12-17T01:09:00","guid":{"rendered":"http:\/\/jaipurhosting.com\/blog\/?p=1333"},"modified":"2019-04-27T07:33:19","modified_gmt":"2019-04-27T02:03:19","slug":"sessions-with-tmux-and-screen","status":"publish","type":"post","link":"https:\/\/www.jaipurhosting.com\/blog\/sessions-with-tmux-and-screen\/","title":{"rendered":"Sessions With Tmux and Screen"},"content":{"rendered":"\n<p><strong>Basic Terminal Session Sharing With A Single Account<\/strong><\/p>\n\n\n\n<p>If an account is held jointly between two or more users, then the sharing of the terminal console is very simple. Neither tmux nor screen require anything out of the ordinary for basic sharing between a single account logged in multiple times. Basic sharing is very easy if you are both logged in as the same user.<\/p>\n\n\n\n<p><strong>Basic sharing with screen<\/strong><\/p>\n\n\n\n<p>In one terminal create a new session for screen, where foobar is the name of your screen session:<\/p>\n\n\n\n<p><strong>screen -S foobar<\/strong><\/p>\n\n\n\n<p>Then in the other terminal, attach to that session.<\/p>\n\n\n\n<p><strong>screen -x foobar<\/strong><\/p>\n\n\n\n<p>That\u2019s it, there were just two steps.<br><strong> <\/strong><\/p>\n\n\n\n<p><strong>Basic sharing with tmux<\/strong><\/p>\n\n\n\n<p>Again, there are only two steps. In the first terminal, start tmux where shared is the session name:<\/p>\n\n\n\n<p><strong>tmux new-session -s shared<\/strong><\/p>\n\n\n\n<p>Then in the second terminal attach to the shared session.<\/p>\n\n\n\n<p><strong>tmux attach-session -t shared<\/strong><\/p>\n\n\n\n<p>That\u2019s it.<\/p>\n\n\n\n<p><strong>Sharing Terminal Sessions Between Two Different Accounts<\/strong><\/p>\n\n\n\n<p>Sharing between two different accounts requires some additional steps to grant the privileges necessary for one account to access another\u2019s session. In some cases, it will require help from the system administrator to prepare the setup.<br><\/p>\n\n\n\n<p><strong> Sharing between two different accounts with tmux<\/strong><\/p>\n\n\n\n<p>For different users, you have to set the permissions on the tmux socket so that both users can read and write it. There is only one prerequiste, that there be a group in common between the two users. If such a group does not exist it will be necessary to create one.<\/p>\n\n\n\n<p>In the first terminal, start tmux where shared is the session name and shareds is the name of the socket:<\/p>\n\n\n\n<p><strong>tmux -S \/tmp\/shareds new -s shared<\/strong><\/p>\n\n\n\n<p>Then chgrp the socket to a group that both users share in common. In this example, joint is the group that both users share. If there are other users in the group, then they also have access. So it might be recommended that the group have only the two members.<\/p>\n\n\n\n<p><strong>chgrp joint \/tmp\/shareds<\/strong><\/p>\n\n\n\n<p>In the second terminal attach using that socket and session.<\/p>\n\n\n\n<p><strong>tmux -S \/tmp\/shareds attach -t shared<\/strong><\/p>\n\n\n\n<p>That\u2019s it. The session can be made read-only for the second user, but only on a voluntary basis. The decision to work read-only is made when the second user attaches to the session.<\/p>\n\n\n\n<p><strong>tmux -S \/tmp\/shareds attach -t shared -r<\/strong><\/p>\n\n\n\n<p><strong>Sharing between two different accounts with screen<\/strong><\/p>\n\n\n\n<p>If you are logged in as two different users, there are three prerequisites to using screen. First, screen must be set SUID and it is necessary to remove group write access from \/var\/run\/screen. The safety of using SUID in this context is something to consider. Then you must use screen\u2019s ACLs to grant permission to the second user.<\/p>\n\n\n\n<p><strong>sudo chmod u+s \/usr\/bin\/screen<br>sudo chmod 755 \/var\/run\/screen<\/strong><\/p>\n\n\n\n<p>In the first user\u2019s terminal, start screen as in the basic sharing above, where foobar is the name of the screen session. Then turn on multiuser mode and add user2 to the ACL, where user2 is the second account to be sharing the session.<\/p>\n\n\n\n<p><strong>screen -S foobar<br> ^A:multiuser on<br> ^A:acladd user2<\/strong><\/p>\n\n\n\n<p>The session can be made read-only for the second user by entering the following ACL change: ^A:aclchg user2 -w \u201c#?\u201d<\/p>\n\n\n\n<p>Then in the other terminal, attach to the first user\u2019s session.<\/p>\n\n\n\n<p><strong>screen -x user1\/foobar<\/strong><\/p>\n\n\n\n<p>It is also possible to put multiuser on and acladd user2 into .screenrc to have it take effect automatically upon starting screen. If the changes are not desired in all screen sessions, then a separate .screenrc configuration file can be specified by using the -c option when starting screen.<\/p>\n\n\n\n<p>Note : Be careful when exiting. If you just exit the shell, it will end the terminal session for all parties. If you instead detach the session then the other user can continue working uninterrupted. In tmux that is ^B-d and in screen that is ^A-d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Basic Terminal Session Sharing With A Single Account If an account is held jointly between two or more users, then the sharing of the terminal console is very simple. Neither tmux nor screen require anything out of the ordinary for basic sharing between a single account logged in multiple times. Basic sharing is very easy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1334,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-categorized"],"_links":{"self":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1333"}],"version-history":[{"count":1,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1333\/revisions"}],"predecessor-version":[{"id":1335,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1333\/revisions\/1335"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media\/1334"}],"wp:attachment":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}