How to configure GNU screen or tmux to reattach to the previous session without using command line...
Starships without computers?
The logic of invoking virtual functions is not clear (or it is method hiding?)
Shouldn't the "credit score" prevent Americans from going deeper and deeper into personal debt?
How can I support the recycling, but not the new production of aluminum?
Can a group have a cyclical derived series?
What professions would a medieval village with a population of 100 need?
Can my boyfriend, who lives in the UK and has a Polish passport, visit me in the USA?
Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?
The teacher logged me in as administrator for doing a short task, is the whole system now compromised?
Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")
In an emergency, how do I find and share my position?
Church Booleans
Is there such a thing as too inconvenient?
Was Switzerland really impossible to invade during WW2?
Does Swashbuckler's Fancy Footwork apply if the attack was made with Booming Blade?
To "hit home" in German
Potential new partner angry about first collaboration - how to answer email to close up this encounter in a graceful manner
Overwrite file only if data
Why didn’t Doctor Strange stay in the original winning timeline?
Defense against attacks using dictionaries
Why does my house heat up, even when it's cool outside?
Bug or undocumented behaviour in Intersection
Are there any plans for handling people floating away during an EVA?
!I!n!s!e!r!t! !n!b!e!t!w!e!e!n!
How to configure GNU screen or tmux to reattach to the previous session without using command line arguments?
How to make screen -R attach to the youngest detached session?Why might tmux only be capable of attaching once per shell session?Is there a tmux equivalent of “screen -D -R”tmux: Set default session for attachIs there a more elegant way to unlink two tmux clients sharing a session from inside tmux?stop node server in tmuxtmux: inner window notify outer sessionStart shell with tmux and attach only to a session if it is unattachedCan attaching to tmux sessions be password protected, similar to gnu screen?How to detach tmux when the shell exits but not when killed from session overview?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
By launching GNU screen or tmux as the initial default shell (set with chsh, for instance), passing arguments seems not to be supported, such as "-d RR" for screen and "attach" for tmux. chsh's argument is the full pathname to a shell file executable (listed in /etc/shells).
For screen, is there an internal command to reattach itself to a previous screen session? Or is there a way to pull the individual processes from the previous screen session into the current session?
For tmux, is there a way to set, in the user configuration file (~/.tmux.conf by default), an option to go directly to the previous session?
After launching tmux without any arguments (which creates a new session), one can manually switch to the previous session (CTRL+B, () and then kill the newly launched session (CTRL+B, :kill-session -a).
configuration login tmux gnu-screen
add a comment |
By launching GNU screen or tmux as the initial default shell (set with chsh, for instance), passing arguments seems not to be supported, such as "-d RR" for screen and "attach" for tmux. chsh's argument is the full pathname to a shell file executable (listed in /etc/shells).
For screen, is there an internal command to reattach itself to a previous screen session? Or is there a way to pull the individual processes from the previous screen session into the current session?
For tmux, is there a way to set, in the user configuration file (~/.tmux.conf by default), an option to go directly to the previous session?
After launching tmux without any arguments (which creates a new session), one can manually switch to the previous session (CTRL+B, () and then kill the newly launched session (CTRL+B, :kill-session -a).
configuration login tmux gnu-screen
add a comment |
By launching GNU screen or tmux as the initial default shell (set with chsh, for instance), passing arguments seems not to be supported, such as "-d RR" for screen and "attach" for tmux. chsh's argument is the full pathname to a shell file executable (listed in /etc/shells).
For screen, is there an internal command to reattach itself to a previous screen session? Or is there a way to pull the individual processes from the previous screen session into the current session?
For tmux, is there a way to set, in the user configuration file (~/.tmux.conf by default), an option to go directly to the previous session?
After launching tmux without any arguments (which creates a new session), one can manually switch to the previous session (CTRL+B, () and then kill the newly launched session (CTRL+B, :kill-session -a).
configuration login tmux gnu-screen
By launching GNU screen or tmux as the initial default shell (set with chsh, for instance), passing arguments seems not to be supported, such as "-d RR" for screen and "attach" for tmux. chsh's argument is the full pathname to a shell file executable (listed in /etc/shells).
For screen, is there an internal command to reattach itself to a previous screen session? Or is there a way to pull the individual processes from the previous screen session into the current session?
For tmux, is there a way to set, in the user configuration file (~/.tmux.conf by default), an option to go directly to the previous session?
After launching tmux without any arguments (which creates a new session), one can manually switch to the previous session (CTRL+B, () and then kill the newly launched session (CTRL+B, :kill-session -a).
configuration login tmux gnu-screen
configuration login tmux gnu-screen
edited 2 days ago
muru
43.8k5 gold badges110 silver badges181 bronze badges
43.8k5 gold badges110 silver badges181 bronze badges
asked 2 days ago
Pedro PalhotoPedro Palhoto
3041 gold badge4 silver badges11 bronze badges
3041 gold badge4 silver badges11 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Nice idea. I'd create a wrapper, say /bin/my-screen that would look
like this:
#!/usr/bin/env sh
screen -d -RR
Make it executable and add it to /etc/shells:
echo /bin/my-screen | sudo tee -a /etc/shells
Make it the default shell:
chsh --shell /bin/my-screen
Notice that some terminal emulators such as xterm do not run shell
defined in /etc/passwd by default but they check $SHELL variable
first.
You can try adding this to your ~/.screenrc:
screen -X screen -d -RR
Notice however that there is a potential problem with that solution -
you won't be able to start screen at all if there are no existing
sessions screen could re-attach. That means that if you set your
screen as your default shell you won't be able to log into your
system.
That's a great workaround, @Arkadiusz, thanks for adding it. I'm still looking for something that could be done if you don't have administrative privileges to the system in question.
– Pedro Palhoto
2 days ago
So how did you usechshto make screen your default shell without root?
– Arkadiusz Drabczyk
2 days ago
chsh -s /usr/bin/screen <login>. In the chsh man page: "A normal user may only change the login shell for her own account; the superuser may change the login shell for any account."
– Pedro Palhoto
2 days ago
Ah, ok I see. Sorry for the confusion. So the problem is that you cannot modify local/etc/shells?
– Arkadiusz Drabczyk
2 days ago
Yes, that is correct, @Arkadiusz.
– Pedro Palhoto
2 days ago
|
show 2 more comments
I have this at the bottom of my zshrc:
[ -z "$TMUX" ] && {
tmux attach || tmux new-session
}
Haven't had any trouble so far; been there for years on thar particular server I think
This mechanism works well for when you start your login with a regular shell. Still looking for a way to do so when screen or tmux are launched directly as the login shell (configured in/etc/shells).
– Pedro Palhoto
yesterday
What's the difference, functionally, between what I did and directly launching it as the login shell? (Even if you managed it, I think it would cripple things like rsync, scp, etc., and restrict you to interactive logins only. This is of course just a guess).
– sitaram
yesterday
For the current use case, crippled protocols are not an issue. The objective was to reduce the number of launched processes to a minimum (there is a FG/BG process quota per user). I find it curious there isn't a configurable way (that I could find about so far) that could attach the previous multiterm session after the screen/tmux session has been launched without command line arguments. Perhaps screen/tmux authors never considered the possibility of command line arguments being unavailable. Knowing how to do so could be useful for some other use case besides the one I stumbled upon.
– Pedro Palhoto
17 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f536123%2fhow-to-configure-gnu-screen-or-tmux-to-reattach-to-the-previous-session-without%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Nice idea. I'd create a wrapper, say /bin/my-screen that would look
like this:
#!/usr/bin/env sh
screen -d -RR
Make it executable and add it to /etc/shells:
echo /bin/my-screen | sudo tee -a /etc/shells
Make it the default shell:
chsh --shell /bin/my-screen
Notice that some terminal emulators such as xterm do not run shell
defined in /etc/passwd by default but they check $SHELL variable
first.
You can try adding this to your ~/.screenrc:
screen -X screen -d -RR
Notice however that there is a potential problem with that solution -
you won't be able to start screen at all if there are no existing
sessions screen could re-attach. That means that if you set your
screen as your default shell you won't be able to log into your
system.
That's a great workaround, @Arkadiusz, thanks for adding it. I'm still looking for something that could be done if you don't have administrative privileges to the system in question.
– Pedro Palhoto
2 days ago
So how did you usechshto make screen your default shell without root?
– Arkadiusz Drabczyk
2 days ago
chsh -s /usr/bin/screen <login>. In the chsh man page: "A normal user may only change the login shell for her own account; the superuser may change the login shell for any account."
– Pedro Palhoto
2 days ago
Ah, ok I see. Sorry for the confusion. So the problem is that you cannot modify local/etc/shells?
– Arkadiusz Drabczyk
2 days ago
Yes, that is correct, @Arkadiusz.
– Pedro Palhoto
2 days ago
|
show 2 more comments
Nice idea. I'd create a wrapper, say /bin/my-screen that would look
like this:
#!/usr/bin/env sh
screen -d -RR
Make it executable and add it to /etc/shells:
echo /bin/my-screen | sudo tee -a /etc/shells
Make it the default shell:
chsh --shell /bin/my-screen
Notice that some terminal emulators such as xterm do not run shell
defined in /etc/passwd by default but they check $SHELL variable
first.
You can try adding this to your ~/.screenrc:
screen -X screen -d -RR
Notice however that there is a potential problem with that solution -
you won't be able to start screen at all if there are no existing
sessions screen could re-attach. That means that if you set your
screen as your default shell you won't be able to log into your
system.
That's a great workaround, @Arkadiusz, thanks for adding it. I'm still looking for something that could be done if you don't have administrative privileges to the system in question.
– Pedro Palhoto
2 days ago
So how did you usechshto make screen your default shell without root?
– Arkadiusz Drabczyk
2 days ago
chsh -s /usr/bin/screen <login>. In the chsh man page: "A normal user may only change the login shell for her own account; the superuser may change the login shell for any account."
– Pedro Palhoto
2 days ago
Ah, ok I see. Sorry for the confusion. So the problem is that you cannot modify local/etc/shells?
– Arkadiusz Drabczyk
2 days ago
Yes, that is correct, @Arkadiusz.
– Pedro Palhoto
2 days ago
|
show 2 more comments
Nice idea. I'd create a wrapper, say /bin/my-screen that would look
like this:
#!/usr/bin/env sh
screen -d -RR
Make it executable and add it to /etc/shells:
echo /bin/my-screen | sudo tee -a /etc/shells
Make it the default shell:
chsh --shell /bin/my-screen
Notice that some terminal emulators such as xterm do not run shell
defined in /etc/passwd by default but they check $SHELL variable
first.
You can try adding this to your ~/.screenrc:
screen -X screen -d -RR
Notice however that there is a potential problem with that solution -
you won't be able to start screen at all if there are no existing
sessions screen could re-attach. That means that if you set your
screen as your default shell you won't be able to log into your
system.
Nice idea. I'd create a wrapper, say /bin/my-screen that would look
like this:
#!/usr/bin/env sh
screen -d -RR
Make it executable and add it to /etc/shells:
echo /bin/my-screen | sudo tee -a /etc/shells
Make it the default shell:
chsh --shell /bin/my-screen
Notice that some terminal emulators such as xterm do not run shell
defined in /etc/passwd by default but they check $SHELL variable
first.
You can try adding this to your ~/.screenrc:
screen -X screen -d -RR
Notice however that there is a potential problem with that solution -
you won't be able to start screen at all if there are no existing
sessions screen could re-attach. That means that if you set your
screen as your default shell you won't be able to log into your
system.
edited 2 days ago
answered 2 days ago
Arkadiusz DrabczykArkadiusz Drabczyk
9,0203 gold badges20 silver badges36 bronze badges
9,0203 gold badges20 silver badges36 bronze badges
That's a great workaround, @Arkadiusz, thanks for adding it. I'm still looking for something that could be done if you don't have administrative privileges to the system in question.
– Pedro Palhoto
2 days ago
So how did you usechshto make screen your default shell without root?
– Arkadiusz Drabczyk
2 days ago
chsh -s /usr/bin/screen <login>. In the chsh man page: "A normal user may only change the login shell for her own account; the superuser may change the login shell for any account."
– Pedro Palhoto
2 days ago
Ah, ok I see. Sorry for the confusion. So the problem is that you cannot modify local/etc/shells?
– Arkadiusz Drabczyk
2 days ago
Yes, that is correct, @Arkadiusz.
– Pedro Palhoto
2 days ago
|
show 2 more comments
That's a great workaround, @Arkadiusz, thanks for adding it. I'm still looking for something that could be done if you don't have administrative privileges to the system in question.
– Pedro Palhoto
2 days ago
So how did you usechshto make screen your default shell without root?
– Arkadiusz Drabczyk
2 days ago
chsh -s /usr/bin/screen <login>. In the chsh man page: "A normal user may only change the login shell for her own account; the superuser may change the login shell for any account."
– Pedro Palhoto
2 days ago
Ah, ok I see. Sorry for the confusion. So the problem is that you cannot modify local/etc/shells?
– Arkadiusz Drabczyk
2 days ago
Yes, that is correct, @Arkadiusz.
– Pedro Palhoto
2 days ago
That's a great workaround, @Arkadiusz, thanks for adding it. I'm still looking for something that could be done if you don't have administrative privileges to the system in question.
– Pedro Palhoto
2 days ago
That's a great workaround, @Arkadiusz, thanks for adding it. I'm still looking for something that could be done if you don't have administrative privileges to the system in question.
– Pedro Palhoto
2 days ago
So how did you use
chsh to make screen your default shell without root?– Arkadiusz Drabczyk
2 days ago
So how did you use
chsh to make screen your default shell without root?– Arkadiusz Drabczyk
2 days ago
chsh -s /usr/bin/screen <login> . In the chsh man page: "A normal user may only change the login shell for her own account; the superuser may change the login shell for any account."– Pedro Palhoto
2 days ago
chsh -s /usr/bin/screen <login> . In the chsh man page: "A normal user may only change the login shell for her own account; the superuser may change the login shell for any account."– Pedro Palhoto
2 days ago
Ah, ok I see. Sorry for the confusion. So the problem is that you cannot modify local
/etc/shells?– Arkadiusz Drabczyk
2 days ago
Ah, ok I see. Sorry for the confusion. So the problem is that you cannot modify local
/etc/shells?– Arkadiusz Drabczyk
2 days ago
Yes, that is correct, @Arkadiusz.
– Pedro Palhoto
2 days ago
Yes, that is correct, @Arkadiusz.
– Pedro Palhoto
2 days ago
|
show 2 more comments
I have this at the bottom of my zshrc:
[ -z "$TMUX" ] && {
tmux attach || tmux new-session
}
Haven't had any trouble so far; been there for years on thar particular server I think
This mechanism works well for when you start your login with a regular shell. Still looking for a way to do so when screen or tmux are launched directly as the login shell (configured in/etc/shells).
– Pedro Palhoto
yesterday
What's the difference, functionally, between what I did and directly launching it as the login shell? (Even if you managed it, I think it would cripple things like rsync, scp, etc., and restrict you to interactive logins only. This is of course just a guess).
– sitaram
yesterday
For the current use case, crippled protocols are not an issue. The objective was to reduce the number of launched processes to a minimum (there is a FG/BG process quota per user). I find it curious there isn't a configurable way (that I could find about so far) that could attach the previous multiterm session after the screen/tmux session has been launched without command line arguments. Perhaps screen/tmux authors never considered the possibility of command line arguments being unavailable. Knowing how to do so could be useful for some other use case besides the one I stumbled upon.
– Pedro Palhoto
17 hours ago
add a comment |
I have this at the bottom of my zshrc:
[ -z "$TMUX" ] && {
tmux attach || tmux new-session
}
Haven't had any trouble so far; been there for years on thar particular server I think
This mechanism works well for when you start your login with a regular shell. Still looking for a way to do so when screen or tmux are launched directly as the login shell (configured in/etc/shells).
– Pedro Palhoto
yesterday
What's the difference, functionally, between what I did and directly launching it as the login shell? (Even if you managed it, I think it would cripple things like rsync, scp, etc., and restrict you to interactive logins only. This is of course just a guess).
– sitaram
yesterday
For the current use case, crippled protocols are not an issue. The objective was to reduce the number of launched processes to a minimum (there is a FG/BG process quota per user). I find it curious there isn't a configurable way (that I could find about so far) that could attach the previous multiterm session after the screen/tmux session has been launched without command line arguments. Perhaps screen/tmux authors never considered the possibility of command line arguments being unavailable. Knowing how to do so could be useful for some other use case besides the one I stumbled upon.
– Pedro Palhoto
17 hours ago
add a comment |
I have this at the bottom of my zshrc:
[ -z "$TMUX" ] && {
tmux attach || tmux new-session
}
Haven't had any trouble so far; been there for years on thar particular server I think
I have this at the bottom of my zshrc:
[ -z "$TMUX" ] && {
tmux attach || tmux new-session
}
Haven't had any trouble so far; been there for years on thar particular server I think
answered yesterday
sitaramsitaram
914 bronze badges
914 bronze badges
This mechanism works well for when you start your login with a regular shell. Still looking for a way to do so when screen or tmux are launched directly as the login shell (configured in/etc/shells).
– Pedro Palhoto
yesterday
What's the difference, functionally, between what I did and directly launching it as the login shell? (Even if you managed it, I think it would cripple things like rsync, scp, etc., and restrict you to interactive logins only. This is of course just a guess).
– sitaram
yesterday
For the current use case, crippled protocols are not an issue. The objective was to reduce the number of launched processes to a minimum (there is a FG/BG process quota per user). I find it curious there isn't a configurable way (that I could find about so far) that could attach the previous multiterm session after the screen/tmux session has been launched without command line arguments. Perhaps screen/tmux authors never considered the possibility of command line arguments being unavailable. Knowing how to do so could be useful for some other use case besides the one I stumbled upon.
– Pedro Palhoto
17 hours ago
add a comment |
This mechanism works well for when you start your login with a regular shell. Still looking for a way to do so when screen or tmux are launched directly as the login shell (configured in/etc/shells).
– Pedro Palhoto
yesterday
What's the difference, functionally, between what I did and directly launching it as the login shell? (Even if you managed it, I think it would cripple things like rsync, scp, etc., and restrict you to interactive logins only. This is of course just a guess).
– sitaram
yesterday
For the current use case, crippled protocols are not an issue. The objective was to reduce the number of launched processes to a minimum (there is a FG/BG process quota per user). I find it curious there isn't a configurable way (that I could find about so far) that could attach the previous multiterm session after the screen/tmux session has been launched without command line arguments. Perhaps screen/tmux authors never considered the possibility of command line arguments being unavailable. Knowing how to do so could be useful for some other use case besides the one I stumbled upon.
– Pedro Palhoto
17 hours ago
This mechanism works well for when you start your login with a regular shell. Still looking for a way to do so when screen or tmux are launched directly as the login shell (configured in
/etc/shells).– Pedro Palhoto
yesterday
This mechanism works well for when you start your login with a regular shell. Still looking for a way to do so when screen or tmux are launched directly as the login shell (configured in
/etc/shells).– Pedro Palhoto
yesterday
What's the difference, functionally, between what I did and directly launching it as the login shell? (Even if you managed it, I think it would cripple things like rsync, scp, etc., and restrict you to interactive logins only. This is of course just a guess).
– sitaram
yesterday
What's the difference, functionally, between what I did and directly launching it as the login shell? (Even if you managed it, I think it would cripple things like rsync, scp, etc., and restrict you to interactive logins only. This is of course just a guess).
– sitaram
yesterday
For the current use case, crippled protocols are not an issue. The objective was to reduce the number of launched processes to a minimum (there is a FG/BG process quota per user). I find it curious there isn't a configurable way (that I could find about so far) that could attach the previous multiterm session after the screen/tmux session has been launched without command line arguments. Perhaps screen/tmux authors never considered the possibility of command line arguments being unavailable. Knowing how to do so could be useful for some other use case besides the one I stumbled upon.
– Pedro Palhoto
17 hours ago
For the current use case, crippled protocols are not an issue. The objective was to reduce the number of launched processes to a minimum (there is a FG/BG process quota per user). I find it curious there isn't a configurable way (that I could find about so far) that could attach the previous multiterm session after the screen/tmux session has been launched without command line arguments. Perhaps screen/tmux authors never considered the possibility of command line arguments being unavailable. Knowing how to do so could be useful for some other use case besides the one I stumbled upon.
– Pedro Palhoto
17 hours ago
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f536123%2fhow-to-configure-gnu-screen-or-tmux-to-reattach-to-the-previous-session-without%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown