Skip to main content

Posts

Showing posts with the label sftp

Solution for com.jcraft.jsch.JSchException: reject HostKey problem on Ubuntu

Just a random investigation with a workaround. So trying to connect to SFTP server using jsch library, but getting a nasty com.jcraft.jsch.JSchException: reject HostKey exception. This host is already present in ~/.ssh/known_hosts file, so it should not be problem, but it is. It turns out this problem happens if SFTP server is running on Ubuntu and strictHostKey is set to true, but it doesn't happen on Linux Fedora. I suppose this is because host entries in the known_hosts file on Ubuntu are encrypted in a different way than in known_hosts on Fedora, so it cannot be recognized or decrypted by JSch library. Now all you need to do is manually add host entries to the file. Basically you just get the public key for the host where SFTP server is running using this command: ssh-keyscan -t rsa sftp_server_ip_address_or_hostname Then copy-paste the output to your local ~/.ssh/known_hosts file. That's all, it should work now. If it doesn't, try to empty known_hosts file complet

Setting up SFTP server in Linux Ubuntu. Command line instructions

Simple step-by-step command line instructions on setting up SFTP server in Ubuntu 12.04, based on http://www.thegeekstuff.com/2012/03/chroot-sftp-setup/ article. 1. Add 'sftpusers' group: sudo groupadd sftpusers 2. Create a home directory for 'guestuser' user that will be added at the next step: sudo mkdir /var/guestuserhomedir As the result of the above command permissions for /var/guestuserhomedir should be 755 (owner: root, group: root). 3. Create 'guestuser' user, add it to the 'sftpusers' group and set a new password for this user: sudo useradd -g sftpusers -d /var/guestuserhomedir -s /usr/sbin/nologin guestuser sudo passwd guestuser 4. Create SFTP directories and set permissions (correct permissions are important): sudo mkdir /var/sftp_upload_dir sudo mkdir /var/sftp_upload_dir/guestuser sudo mkdir /var/sftp_upload_dir/guestuser/incoming sudo chown guestuser:sftpusers /var/sftp_upload_dir/guestuser/incoming sudo chmod 777 /var/sftp_u