In Java, access to shared resources can be controlled by using synchronized methods. An instance method is declared to be a synchronized method by adding the modifier synchronized to its declaration. For example:
The basis of using ssh without typing your password is public key based authentication. You need to generate a pair of public/private keys for this.