Putty and SSH problem "Server refused to allocate pty"

Hey

I just ran into this error on my Pi when I have tried to log into it via ssh from putty:

Server refused to allocate pty

It authenticates and then it kicks me out, the only resolution is to reboot the pi from within osmc whereupon ssh starts working again.
Disabling the ssh service via the “my osmc” icon doesnt work, restarting the media centre service doesnt work, restarting the ssh service via “sudo service ssh restart” may have worked but it was just easier to reboot than to hoak out a keyboard because there is no terminal within osmc (why doesnt someone build a limited python driven terminal emulator??).

I found a command to check the max number of tty (pseudo terminals) which was 4096:

cat /proc/sys/kernel/pty/max

I believe I have somehow maxed out the number of tty’s on my system although I have no idea how I managed to start over 4000 terminal sessions.

I tried the following steps which may or may not have resolved the problem:

sudo apt-get remove openssh-server
sudo apt-get install openssh-server

But as it only happened after my server being on for like a day its pretty hard to test.

The only thing I can think which I have done which would have caused this problem is that i have been trying to get sopcast working in plexus and each time you click on a sopcast link it loads a shell script which loads quemu which loads sp-sc-auth (sopcast).
The shell scripts has no exit command so would continually trying many sopcast links, which then fail to load, use up terminal sessions until i can no longer log in remotely?

I can still log in via winscp and access my pi via the remote app.

Firstly can anyone tell me how to kill all tty sessions if this happens again so i could maybe cron a script to periodically run?
And secondly if i needed to run this script from the remote control app, how would i do it?

Ok if i need to run the script from yatse you would do it by adding a custom command as follows:

Custom command
Add from media center
call built in
System.Exec(/home/osmc/scripts/kodirestart.sh)

So all I need to know now is how to kill idle tty terminal sessions via a script.

Cheers

A little google and i find this example:

Install cron and run this script (second answer) in cron every hour and perhaps set in to amin 45

Hey

Thanks thats pretty handy, I had seen the w command when I was trying to figure out what the problem was but before I figured out how to close the numerous tty sessions I wanted to know if that was likely to actually be the problem.

If it is the sopcast thing then I am done experimenting and its not likely to happen again. If not that then what is likely to be the cause?
Would unterminated scripts result in multiple open tty sessions? Testing it now it doesnt appear to result in any different information in w. So i dont think thats actually the culprit.
I have been playing with other addons which do lots of scraping, would that result in maxing out the number of tty sessions?
If its not addon related its osmc related because I only just reinstalled osmc the other day and prior to me breaking python and having to reinstall osmc I have never seen this message on a system which only gets rebooted very rarely. The only new variable is a load of streaming addons and the most recent release of osmc.
Id hate to have to start rebooting my system once or more a day or run some sort of kill script because of a problem i cant diagnose. And as ill be going away for christmas soon id like to be able to shell in remotely.

Im also concerned that its could be a security issue. Before the recent reinstall there were logs which showed numerous failed login attempts from randoms ips, hundreds of them presumably some sort of bot or something and I wasnt worrying about it becuase it was as secure as I needed it to be.
However now i see very little in the way of logging about failed ssh attempts (which i dont believe stopped) which leads me to believe that this may have been something i did on the last install which i cant really remember now. I have hazy recollections about trying to secure the pi a bit more with a firewall or ssh rejection after 3 attempts or something.

After a bit of googling i recall stuff about fail2ban which will block too many failed login attempts. I dont know if this is how i did it before, im sure there are plenty of options of how to do that in linux but I have installed fail2ban as per here:

im hoping that will stop this being an issue going forward without having to worry about rebooting to be able to login remotely.

Are you port forwarding port 22?? Because you 1000% should not be forwarding port 22 from the outside world. You should set up your router to either be passing a randomly picked, non-standard port from the WAN side to port 22 on your Pi on the LAN side, or simply change the SSH port on the Pi to a random, non-standard port and forward that.

1 Like

fail2ban isn’t a bad idea, changing the default port is also a good idea, one doesn’t exclude the other =)

And the script if you ever need it again.

1 Like