1

I'm working with someone who's been doing simulations on various computers and FTPing the results to a website using a script and the basic mac ftp command basically something like (this is not exact just what i remember from when i last looked at it)

ftp -i username@host password
cd /dir/
put file 1
put file 2
...

and so on...

I need to upgrade this process to use SFTP for security purposes, but there's no way that I can tell to put the password in a single line script for the SFTP program that's built into mac OS X. Is there some other way to do this? I tried using something called LFTP which seemed to connect to the server but the files would always stay at 0% when they were trying to transfer. Any help would be appreciated.

  • learn him to use public key authentication. It works on one-line and is more secure then password written on command line in plain text. Or if you really insist on writing password on commandline, there is tool sshpass (certainly also for Mac), but I can't recommend it. – Jakuje Jan 22 '16 at 22:10
  • I saw sshpass but couldn't seem to figure that out. I understand the concept of the public key authentication but I don't do this stuff ever day so I need a little more direction. I guess i need to generate a key from the server itself and provide it to the user then they can connect just using the username and the key will authenticate them right? Can you send some specific command line examples of what it would look like to assign/create the key as well as what it would look like on client side to connect. As I said I don't do this stuff every day so i'm stumblnig around a lot. – Brendan Jan 25 '16 at 17:00
  • Another solution would be getting a copy of Transmit and setup its folder sync functionality. – EDP Jan 25 '16 at 17:36
1

I guess i need to generate a key from the server itself and provide it to the user then they can connect just using the username and the key will authenticate them right?

No. Generate the key on client (ssh-keygen) and upload the public key to server. For example using ssh-copy-id, if the ssh is allowed on the server. There are many how-to's around the internet, so I believe you will be able to figure out.

Then connecting would work like sftp username@host (without password). If you have some batch, you can provide it to sftp using -b option. For more info, consult manual pages for sftp or the other above mentioned tools.

  • i've been able to generate a public key on a mac that i'm using to test using the ssh-keygen tool but not sure how to put the public key onto my cygwin server so i can login password free. I tried using ssh-copy-id but it said command not found. I am searching the web for what should seem like a simple answer on this but i'm coming up a bit blank. – Brendan Jan 26 '16 at 21:03
  • You can download recent ssh-copy-id, if it is not packaged on your mac. It should be the safest way if you know password. – Jakuje Jan 26 '16 at 21:08
  • Ok i think i copied my key up using instructions i found here commandlinefu.com/commands/view/188/… but when i try to sftp to my server it just says connection closed. Not sure if there's more I need to do. Do I have to do something on the server side at this point to like tell it to accept that public key for access. It seems weird to me that access could be granted by an entirely client sided command like that. – Brendan Jan 26 '16 at 21:10
  • Of course you need to provide password to ssh-copy-id. Anyway check the server error log. There should be some note why the connection failed. – Jakuje Jan 26 '16 at 21:11
  • I downloaded ssh-copy-id using brew but when i tried to run it to the server it gives me the following: INFO:attempting to log in with new key(s), to filter out any that are already installed. /usr/local/bin/ssh-copy-id: ERROR Connection Closed by <ip address of server> – Brendan Jan 26 '16 at 21:15
0

So in the end I never got public key authentication working and i'm sure it's some kind of permissions issue because when i ssh/sftp into the server i can't even cd into the .ssh directory without a permissions error from cygwin. Since I couldn't figure out how to fix this, but I was at least able to get permissions working enough that I could succesfully sftp/ssh from my mac I just ended up installing LFTP which let me use a script that included the password. It wasn't pretty but I made it work. Thanks for everyone's help on this. In the end it looks like most of my problem was cygwin related.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .