I am new to Linux and have been using Ubuntu as my OS on my VPS. After exploring the various Linux options available, I concluded that AlmaLinux was the best choice for servers. I am happy with my decision, especially as a beginner with Linux.
Currently, I am facing an issue with maintaining the connection in PowerShell, which disconnects after a few minutes. I have already looked in all the obvious places, but the issue persists. I understand that as an alternative, I could use tools like tmux
or screen
, but I prefer those options as a last resort.
The main places that have been suggested for me to tweak are:
Configuration:
~/.ssh/config
/etc/ssh/ssh_config
/etc/ssh/sshd_config
I am now trying to find out if there are any other locations that I may be unaware of.
Hey there! Welcome to the world of Linux and AlmaLinux — great choice for servers, especially if you’re just getting started. I know how frustrating it can be when your SSH session drops out after just a few minutes. I’ve been there!
It sounds like your connection from PowerShell (likely using OpenSSH) to your AlmaLinux VPS is timing out due to inactivity. This is usually caused by either your client, server, or even your network/firewall thinking the connection is “idle” and cutting it off. Here’s a step-by-step guide to help you fix it — no tmux or screen required (though they’re great backup tools later on).
Step 1: Fix Keep-Alive Settings on the Server (AlmaLinux)
SSH has a setting that tells the server to “ping” the client occasionally to keep the session alive.
- SSH into your AlmaLinux server.
- Open the SSH server config: sudo nano /etc/ssh/sshd_config
- Add or edit these two lines: ClientAliveInterval 60 ClientAliveCountMax 3This means every 60 seconds, your server will check if you’re still there. If it doesn’t hear back after 3 tries, it will close the session (so, 3 minutes total).
- Save the file and restart SSH: sudo systemctl restart sshd
Done! That helps the server not give up on you so easily.
Step 2: Add Keep-Alive on Your Windows (PowerShell) Side
Now let’s make sure your client is also trying to keep things alive.
- On your Windows machine, go to: C:\Users.ssh\
- Create or edit a file called config (no extension).
- Add this: Host * ServerAliveInterval 60 ServerAliveCountMax 5That tells your client to send a little “ping” every 60 seconds, and it’ll try 5 times before giving up (so about 5 minutes of leeway).
- Save and restart your SSH session.
Now both sides are checking in on each other regularly.
Step 3: Check for Auto-Logout (TMOUT)
Sometimes Linux is set to log you out after X minutes of doing nothing, even if the SSH connection is alive.
On your server, after logging in, run:
echo $TMOUT
If it returns something like 300, that’s 5 minutes! To remove it:
- Run: unset TMOUT (just for that session)
- Or edit /etc/profile or files under /etc/profile.d/ and comment out or delete any line like: export TMOUT=300
Log out and back in to make it stick.
1 Like
Hi there, thank you for your help and advice! I am not quite sure with your step 2 and 3. Step 2 being a command outside the terminal and step 3 does not do anything or the latter path leads to an empty folder.
Hey so step 2 is on your powershell on your machine not the VPC Alma machine.
For step 3, let me get back to you tomorrow.
1 Like
Quick question could you try to ssh using putty instead of powershell just for fun and see if you still have the issue ?
1 Like
I have resolved the issue.
- /etc/ssh/sshd_config (Server Configuration)
- ClientAliveInterval 60
- ClientAliveCountMax 60
- ~/.ssh/config (User-Specific Client Configuration)
- Host *
ServerAliveInterval 60
ServerAliveCountMax 60
- /etc/ssh/ssh_config (Global Client Configuration)
-ServerAliveInterval 60
-ServerAliveCountMax 60
The values all need to match and there was also a ServerAliveCountMax missing from one of the configuration files.
My confidence in AlmaLinux continues!
Many thanks for your input Tristan.
1 Like