Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to upload a file to a server.

The server uploads using SFTP. After authentication, any command execution is forbidden, so I cannot SSH directly in, I need to get directly into the SFTP subsystem.

For instance.

ssh -N works fine, except I can't SFTP anything.

However, I can do sftp just fine.

Problem: I need to automate this, the authentication is keyboard-interactive, not key-based. I don't own the server I'm connecting to, they simply said "Here's the password, upload the files every week." And nobody over there knows anything about keys or stuff like that.

sftp -b Batch scripts won't allow keyboard interactive auth.

I'm sick of manually uploading the file. They sent the 8-charecter password over unencrypted email and it contains 3 of the same numbers at the end and one dictionary word (ie "Words777") -- lets pretend security really isn't an issue here.

Can I make the SSH key from just the password? Remember, I don't have access to the other server. Can I script this some way? I've attempted using different packages, and even rsync to do the upload, but they all want to access SSH directly instead of directly getting into the SFTP subsystem.

share|improve this question

I think that if you create a ssh key without protecting it with a "passphrase", you can skip the keyboard interactive part and thus easily create the upload script you need. See for example here :

ssh-keygen -t rsa -C "Your Name" -f your_key

This will create the necessary files, you then just have to copy the public one (*.pub) on the remote server.

share|improve this answer
I don't have access to the other server. – Incognito Apr 28 '11 at 17:03
You only need the password to copy the public key on the server. It remain to check if the server is configured to support key authentication. – enzotib Apr 28 '11 at 17:28
Where on the server? I only have access to a small sub directory. – Incognito Apr 28 '11 at 17:51
@user11239: You only need access to the file ~/.ssh/authorized_keys under your remote home directory. Here a guide: – enzotib Apr 28 '11 at 19:11
Not everyone has access to ~/.ssh/, so this is not always an option - unfortunately. – tuomassalo Feb 7 '13 at 14:42
up vote 2 down vote accepted

Install Expect that lets you script for situations like this.

sudo apt-get install expect

Set up a shell script


# Sorry for the offensive "assword", it's to cope with "Password" and "password".

VAR=$(expect -c "
  spawn sftp $USER@$HOST

  expect \"assword:\"
  send \"$PASS\r\"

  expect \"\\\\$\"
  send \"ls\r\"

  expect -re \"$USER.*\"
  send \"exit\"

echo "==============="
echo "$VAR"
share|improve this answer

Use Socat.


(sleep 2; echo password) | socat - EXEC: "sftp -o batchmode=no -o PubkeyAuthentication=no -b batchfile user@host",pty,setsid,ctty
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.