I don't know why I'm getting the dreaded "Your post appears to contain code that is not properly formatted as code" error on this post. Here is the text of my post as I originally wanted to post it:

I have had port forwarding from my Windows 10 host to my Ubuntu Virtual Box guest working perfectly for over three years, and then suddenly after a reboot of the guest yesterday PUTTY stopped connecting.

I haven't changed any settings, it just stopped working. I have investigated and tried a lot of suggestions I found on the internet, but it's still not working. Here are the details:

 1. On the Ubuntu guest, I have confirmed that the sshd daemon is running

<pre><code>$ ps aux | grep sshd
jryan    19096  0.0  0.0  61376  3036 ?    Ss  14:15  0:00 /usr/sbin/sshd</code></pre>

2. On the Ubuntu guest, I can successfully SSH into localhost on port 22

<pre><code>$ ssh localhost
jryan@localhost's password:
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-108-generic x86_64)

3. On the Ubuntu guest, I have confirmed that sshd is listening on port 22

<pre><code>netstat -lp --inet
tcp    0    0 localhost:ssh       *:*     LISTEN
tcp    0    0       *:*     LISTEN</code></pre>

4. Again, with nmap

<pre><code>$ sudo nmap -sS -O localhost/24
22/tcp    open  ssh</code></pre>

5. When I ssh from the Windows 10 Host (using Putty), it just hangs for 60 seconds and then I get an error "Server unexpectedly closed network connection". I then opened up a Windows BASH session to run ssh from the command line.

<pre><code>jryan@JIMSURFACEPRO4:/mnt/c/Windows/System32$ ssh -vv jryan@ -p 60022
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to [] port 60022.
debug1: Connection established.
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_rsa type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_rsa-cert type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_dsa type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_dsa-cert type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_ecdsa type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_ecdsa-cert type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_ed25519 type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
ssh_exchange_identification: Connection closed by remote host</code></pre>

6. I have confirmed that port forwarding is properly set up on the virtual machine:

<pre><code>VBoxManage showvminfo
NIC 2:           MAC: 080027775E38, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 2 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 2 Rule(0):   name = ssh, protocol = tcp, host ip = , host port = 60022, guest ip = , guest port = 22</code></pre>

7. I have confirmed that port 60022 is open on the Windows host

<pre><code>c:\Program Files\Oracle\VirtualBox>netstat -a

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP             JimSurfacePro4:0       LISTENING
  TCP             JimSurfacePro4:0       LISTENING
  TCP            JimSurfacePro4:0       LISTENING
  TCP            JimSurfacePro4:0       LISTENING
  TCP            JimSurfacePro4:0       LISTENING
  TCP           JimSurfacePro4:0       LISTENING
  TCP          JimSurfacePro4:0       LISTENING
  TCP          JimSurfacePro4:0       LISTENING
  TCP          JimSurfacePro4:0       LISTENING
  TCP          JimSurfacePro4:0       LISTENING
  TCP          JimSurfacePro4:0       LISTENING
  TCP          JimSurfacePro4:0       LISTENING
  TCP          JimSurfacePro4:0       LISTENING
  TCP          JimSurfacePro4:0       LISTENING
  TCP           JimSurfacePro4:0       LISTENING</code></pre>

8. I have set up Windows Firewall rules allowing all TCP connections (inbound and outbound) on port 60022

9. I checked the logs on the Ubuntu guest. Nothing is written to `/var/logs/auth.log` or `/var/logs/syslog` when I attempt the connection.

10. Here is my `/etc/ssh/sshd_config` from the Ubuntu host:

<pre><code>jryan@medstro-dev-jim:~$ cat /etc/ssh/sshd_config
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
Protocol 2,1
AllowUsers jryan
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
PasswordAuthentication yes
LoginGraceTime 240
PermitRootLogin without-password
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
ClientAliveInterval 60
ClientAliveCountMax 20
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'
UsePAM yes</code></pre>

I've run out of ideas here and could really use some help. Please let me know if you have any questions.

In order to get the "code not formatted as code" error to go away, I removed all the <pre> and <code> tags, and instead selected each code block and pressed CTRL-K as instructed, which enabled me to post, but it makes the formatting look horrible. The code is not properly formatted as code.

To fix it, I had to remove the numbering so that the explanatory paragraphs didn't start with a number. Is there a reason why you can't mix code blocks with numbered paragraphs?

Virtual Box: Port Forwarding for SSH from Win10 Host to Ubuntu Guest Stopped Working

How can I get my code blocks to format properly?

  • 4
    Specifically: inside lists you need an additional four spaces of indentation. – jonrsharpe Feb 4 '17 at 22:00
  • @jonrsharpe: I suppose the real bug is that the check seems to be blindly assuming that 4 spaces = code block, and 1) isn't aware of other ways of formatting code blocks, like <pre><code>, and 2) doesn't recognize that more than four spaces are needed if the code is inside a list. The former leads to false positives (as described by the OP above), the latter to false negatives. – Ilmari Karonen Feb 4 '17 at 22:13

Browse other questions tagged .