Allow connection sshd from other hosts

I set up an SSH server using Cygwin on windows. I was able to test it localy (ssh myAccount@localhost) but I encountered an error when trying from a distant machine.

ssh_exchange_identification: Connection closed by remote host

We have to allow connection from a distant machine inside /etc/hosts.allow on the server.
The syntax of this file is

<services separated by coma>:<hosts or IP separated by coma>[:command]

where command is the command to execute on a connection attempt

So I remove the PARANOID deny from the allow file (!?) and explicitly logged connection attempts from ssh.

# hosts.allow   This file describes the names of the hosts which are
#               allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
ALL : localhost 127.0.0.1/32 [::1]/128 : allow
ALL : PARANOID : deny
sshd: ALL
# hosts.allow   This file describes the names of the hosts which are
#               allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
ALL : localhost 127.0.0.1/32 [::1]/128 : allow
# sshd: ALL
# same directive while keeping track of attemps
shd: ALL: spawn (echo "Attempt from %h %a to %d at `date` by %u" | tee -a /var/log/sshd.log)

Write and read to a samba shared directory using java (JCIFS)

Challenge of the day: publish a file to a microsoft shared directory and then re-read it.

Windows OSes rely on the SAMBA protocol to share files and directories. Thanks to the JCIFS project( http://jcifs.samba.org/), an open source library, we can access theses kind of shares via java.

Under linux, we could have performed it a the shell level using the SMBclient command line utility.

The example is pretty self explanatory, just remember to add jcifs-1.2.25.jar to your classpath and to adapt the authentication parameters to your real login in the url.

import jcifs.smb.*;
public class SMBClient {
  public static void main(String[] args) {
    try{
      // jcifs.Config.setProperty( "jcifs.netbios.wins", "192.168.1.220" );
      //smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]][?[param=value[param2=value2[...]]]
      String url="smb://domain;user_name:user_password@server_name/directory/test_file.txt";
      String content="hello !";
      SmbFileOutputStream out = new SmbFileOutputStream(url);
      out.write(content.getBytes());
 
      System.out.println("File written, now trying to re-read it:");
      SmbFileInputStream in = new SmbFileInputStream(url);
      byte[] b = new byte[10000];
      int n;
      while(( n = in.read( b )) > 0 ) {
        System.out.write( b, 0, n );
      }
    }catch(Exception e){
  System.out.println(e);
  }
 }
}

Thanks to Cyril for the challenge 🙂 and to the forums of developpez.net (in french) for an example.