122

When I want to connect to my server like this

ssh -a username@my-server.de -p 22

it gives me two error messages:

PTY allocation request failed on channel 0
shell request failed on channel 0

When I use the parameter -T the first error message goes away. But how to fix the second one? I can't connect. To other servers I can connect without any problems.

I'm on MAC OS 10.9.

The parameter -v shows me this debug output:

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to xxx.your-server.de [188.40.3.15] port 22.
debug1: Connection established.
debug1: identity file /Users/xxx/.ssh/id_rsa type -1
debug1: identity file /Users/xxx/.ssh/id_rsa-cert type -1
debug1: identity file /Users/xxx/.ssh/id_dsa type -1
debug1: identity file /Users/xxx/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version mod_sftp/0.9.8
debug1: no match: mod_sftp/0.9.8
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 55:f5:ca:ca:01:45:0f:7b:71:0a:1f:ba:9e:25:17:fb
debug1: Host 'xxx.your-server.de' is known and matches the RSA host key.
debug1: Found key in /Users/xxx/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/xxx/.ssh/id_rsa
debug1: Trying private key: /Users/xxx/.ssh/id_dsa
debug1: Next authentication method: password

After I enter the password, I get this:

debug1: Authentication succeeded (password).
Authenticated to xxx.your-server.de ([xxx.xxx.3.15]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = de_DE.UTF-8
shell request failed on channel 0
finnmglas
  • 1,626
  • 4
  • 22
  • 37
user1895268
  • 1,559
  • 3
  • 11
  • 23
  • 6
    The client is requesting a shell session with a TTY and the server is rejecting it. The server doesn't provide the client with a detailed reason why the request was rejected. You need to troubleshoot this on the server rather than the client. – Kenster Nov 19 '14 at 19:25
  • Thank you for your answer. You're right, the server does not provide this request. I don't know ho to find out where the problem is. I read some other posts before but they didn't match exactly my problem. Can anybody give me some hints, please? – user1895268 Nov 20 '14 at 08:14
  • 4
    Try `ssh [-neccessary options] /bin/bash -i`. This might give a more informative error message from the server side (e.g. "permission denied" or "segmentation fault") – Hans Lub Dec 07 '14 at 10:29
  • 11
    The `debug1: Remote protocol version 2.0, remote software version mod_sftp/0.9.8` line indicates that the remote server is proftpd+mod_sftp, and the mod_sftp module does not implement/support shell requests, only SFTP/SCP. Thus the `shell request failed` error. – Castaglia Feb 21 '16 at 18:48
  • 2
    when the server is jenkins it only supports a limited command set, not a shell. So it responds also with "shell request failed on channel 0" when given an accepted command like "help" it works fine. – U.V. Dec 16 '20 at 13:18

23 Answers23

35

PTY allocation request failed on channel 0

There is a limit of 256 pseudo terminals on a system. Maybe you have an application that is leaking pseudo terminals. Use

lsof /dev/pts/*

to see what processes have open pseudo-terminals

shell request failed on channel 0

I was getting this error (without PTY allocation error). It turns out that one of my applications (QtCreator 3.0.?) was leaking Zombie processes. Other users were able to log in so I might have been hitting my per user process quota (if there is such a thing). I've updated to QtCreator 3.3. So far so good.

vharron
  • 1,138
  • 11
  • 20
  • How to check that on windows, my remote machine is linux however I connect to this remote machine using ssh on a Windows computer using GitBash. How to do this command on Windows – Hana90 May 09 '18 at 07:20
  • 5
    The OP said they are on MacOS. Is this solution intended to work on MacOS? When I tried it (MacOS 10.15.5), I got: `lsof: status error on /dev/pts/*: No such file or directory`. – Jeremy Sep 10 '20 at 04:56
  • On which system, client or server? It's not clear from the answer. – Victor Sergienko Aug 29 '23 at 18:23
32

unmount and mount /dev/pts worked for me

umount /dev/pts

mount devpts /dev/pts -t devpts

Reference: http://www.iitk.ac.in/LDP/LDP/lfs/5.0/html/chapter06/proc.html

rajagopalx
  • 3,012
  • 9
  • 41
  • 52
16

I had the exact same error trying to connect via ssh to my server. As I can see you're using a server provided by Hetzner connecting to it on port 22:

debug1: Connecting to xxx.your-server.de [188.40.3.15] port 22.

The offical wiki/documention from Hetzner says:

Protocol for encrypted remote diagnostics for servers/computers(consoles). The SSH port to be used is 222.

So you have to connect via port 222:

ssh -p 222 username@my-server.de
ThreeCheeseHigh
  • 1,429
  • 5
  • 22
  • 40
  • 1
    this is unrelated to a PTY allocation error – math Jul 15 '22 at 15:28
  • Not even closely related to the question ^^ – aefxx Sep 07 '22 at 09:03
  • It is not related to the error, but the same error leads me to this question and changing the port to 222 solved my error. So it is related in a way that the error message might be misleading for the connection you are trying to establish – makkus Jul 18 '23 at 15:08
9

shell request failed on channel 0

mean you don't have shell or remote commands access, fix your user permission on server to have shell access or if you just want tunneling use -N and -T options

ewwink
  • 18,382
  • 2
  • 44
  • 54
8

I solved a similar problem with one of our users who was used only for ssh port forwarding so he don't need to have access to PTY and it was prohibited in .ssh/authorized_keys file:

no-pty ssh-rsa AAA...nUB9 someuser

So when you tried to log in to this user, only message

PTY allocation request failed on channel 0

was returned. So check your user's authorized_keys file.

Ondrej Homolka
  • 111
  • 2
  • 7
8

Try this:

vi /etc/security/limits.d/20-nproc.conf
*          soft    nproc     4096   # change to 65535 
root       soft    nproc     unlimited
xmduhan
  • 965
  • 12
  • 14
  • This is what it was for me. I had just set some values in security/limits.conf that I normally set on users, but somehow my low value was now too low. Apparently a 50 process limit isn't enough anymore. Something must be starting a bunch of processes on login. Linux is getting bloated! – deltaray Oct 18 '22 at 02:11
5

Just add these lines to your /etc/mtab and /etc/fstab, and reboot the system.

none    /dev/pts    devpts    defaults    0    0
Rudie
  • 52,220
  • 42
  • 131
  • 173
Mansur Ul Hasan
  • 2,898
  • 27
  • 24
  • 1
    This worked. On a live CD, you can also do: $ mount -t devpts none /target/dev/pts; chroot /target – Michael Galaxy Dec 18 '15 at 15:27
  • if I use Git bash to connect to aws server, and got this problem. should I modify these files from the main Git bash directory at Program Files? –  Apr 27 '16 at 10:53
  • 1
    Useful tip: you can run a command without logging in and allocating a pty, e.g. `ssh root@example.com '/sbin/reboot'` – Robert Calhoun Jun 24 '16 at 21:09
  • 75
    But what does this code do. You should provide an explanation – Tristan Jul 02 '16 at 15:55
  • 1
    We did this operation (change fstab & mtab and reboot) and it worked... for a while. Apparently it was the reboot that resolved the issue, and now our suspicion is that the remote machine is running out of resources. – Steven the Easily Amused Aug 09 '17 at 17:35
  • [I don't think you should be editing /etc/mtab see this post](https://askubuntu.com/a/754275/323009). – PatS Sep 18 '18 at 22:42
4

just found out, what was the problem in my case (provider strato): I had the same problem with output "shell request failed on channel 0" in the end.

I have to use the master password with the web-domain name as login. (In German www.wunschname.de, where wunschname is your web-address.)

A ssh login with sftp-user names and the corresponding passwords is without success. (Although scp and sftp works with these sftp users!)

feli_x
  • 149
  • 1
  • 8
3

It's an old question, but if someone gets here like me...

This might be result of a wrong date in the server. If you are working with an embedded system this might be the cause... So check your date:

$ date
3

I also faced the same issue. Just restarting my servers solved the issue.

Vivek Garg
  • 2,115
  • 1
  • 20
  • 17
3

If you are trying to test your github ssh key write

ssh -T git@github.com

instead of ssh -t git@github.com

Ahmed Magdy
  • 1,054
  • 11
  • 16
3

If you come to this Q&A for sftp while ssh is working, and you are getting:

subsystem request failed on channel 0

make sure /etc/ssh/sshd_config contains the following line(s):

# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server

They are there by default, but might have been removed for hardening purposes.

stackprotector
  • 10,498
  • 4
  • 35
  • 64
2

rebooting the instance from AWS console worked for me. There was a service that was leaking file connections that lsof helped find.

randhir singh
  • 133
  • 1
  • 8
2

This is what which helped me from the various answers provided.

  • Try logging in as root, that will get you in most of the times
  • Try logging in as a different user, it successful, it means that the problem is with a specific account & it implies that there are some process(es) already started by the problematic account which are consuming resources preventing login(most likely no of processes)
  • Increase the limit in /etc/security/limits.d/20-nproc.conf as mentioned by xmduhan above
  • Try to ssh again, it should work
Aejaz
  • 100
  • 8
2

In my case, my sshd_config contained the value

PermitTTY No

I have to change this to

PermitTTY yes

To log in, I used ssh user@address /bin/bash -i

This gives me a shell without PTY. I then used sed to edit the file:

sed -e '/PermitTTY.*/PermitTTY yes/' < /etc/ssh/sshd_config > sshd_new

Then

sudo -S cp sshd_new /etc/ssh/sshd_config

DAmann
  • 174
  • 7
1

I encountered this error while using my git bash. I was able to solve this by re-installing git for windows. More details in this answer.

user3885927
  • 3,363
  • 2
  • 22
  • 42
1

This was happening when I was trying to use sudo on ssh -t git@github.com after adding my local user's public key to github

Just a head's up to the google happy people like me

Jonathan DS
  • 2,050
  • 5
  • 25
  • 48
  • Omg. Wasted so much time on this. I was using an "Administrator" powershell instance. Closed and used a non-elevated shell, and it worked fine. Ty – Steve Dec 22 '22 at 19:32
1

Just rebooting a AWS instance works for me to clear the error shell request failed on channel 0

0

remounting /dev/pts works for me. you can do this remotely via ssh if you run ssh like this against the affected machine. ssh doesn't request a tty when running commands like this and therefore this will allow you to remount /dev/pts remotely

ssh user@host -- 'mount -o remount,rw /dev/pts'

0

I occasionally see this when spinning up a VM. Our automation system starts applying updates, so depending on timing can hit an update to critical packages.

Upshot - this might happen if ssh or other related packages are being updated on the destination machine.

Criggie
  • 235
  • 5
  • 14
0

Should a person find themselves reading this QA while they are trying to ssh into a NetGear ReadyNAS device, be sure that the "rsync only" checkbox is unchecked in the dialog box for the ssh service in the admin interface.

Krista K
  • 21,503
  • 3
  • 31
  • 43
0

As you already found the -T flag that create a PTY, I will just respond to the second part:

shell request failed on channel 0

You should pass a command:

ssh username@my-server.de -p 22 help

After reading back the manual here: https://www.jenkins.io/doc/book/managing/cli/, I find it not really clear that it would not work without a command. But as stated by @U.V., the ssh interface is not a console interface, rather a connection utility. So you need to pass a command...

If someone from the "jenkins" team pass accross this post, it would be great that if we pass no command, the help would show up :-)

jehon
  • 1,404
  • 15
  • 21
-3

try with option -NT

ssh -NT ...

Shahid
  • 51
  • 3