Posted by on October 24, 2011

I’ve modified a simple wrapper for the libssh2 library that now has the following functionality:

  • Code moved to separate classes to allow reusability
  • Multiple sessions to different servers can be achieved with a few lines of code
  • A Session can be passed to the operator class allowing operations (commands sent to it), more will be added
At the current time it connects fine to OSX and Linux sshd however I can’t connect to ESXi even with the correct password it reports incorrect, However I think I Can resolve this shortly.
Original wrapper (designed for iOS) can be found from in his Git Repo.
Download here: SSH Wrapper
To use the wrapper add the files in the zip to your project, include the headers (ensure you’ve added the correct frameworks and the libssh2 library) etc. Example below:-

sshServer *server = [[sshServer alloc] init];

[server setSSHHost:@”″ port:22 user:@”dan” key:@”” keypub:@”” password:@”XXXXX”];

sshConnector *connection = [[sshConnector alloc] init];

[connection connect:server];

if ([server connectionStatus]) {

         NSLog(@”Server 1 connected”);


NSLog(@”%@”,[sshOperator execCommand:@”uname -a” sshServer:server]);

[connection closeSSH:server];

[connection release];

[server release];



Posted in: Apple, Xcode


  1. James
    August 26, 2012

    will this work with executable files that aren’t builtin with mac or linux?

  2. dan
    September 6, 2012

    What does that mean?

  3. Jan Galler
    September 8, 2012

    I’m trying to use your classes and libssh2 with ARC, 64bit on Mac. But, I’ve several problems at the moment. Starts with: how to build libssh2 and include it? I’ve runned over all commands in INSTALL instructions, but where is the product located now? Beacause I dont know what to do, I tried it with the files from the original SSHCore. But of course, they’re compiled for iOS and not 64bit…
    Can you help me, maybe?

  4. dan
    September 9, 2012

    Hallo Jan, I’ll look into it.. I’ve not done any dev for a while so not sure of any changes with xcode 4 / ARC and 64bit..

  5. Jan Galler
    September 9, 2012

    Dear Dan,
    I’ve done it. Really ‘easy’, if you know who. Just run all instructions in the INSTALL file of libssh2. It looks for the target architecture. The dynamic lib you find ‘somewhere’, just include it. Doesnt work with ARC but that’s ok. I’ve found some parts here:

  6. dan
    September 11, 2012

    Ah fantastic, let me know if there is anything else 🙂

  7. Hashem
    September 12, 2012


    Thanks for this, this was very helpful. When I’m executing your code, however, I get this:

    2012-09-12 19:28:57.237 xxxTest[12013:303] Connection Succesful
    2012-09-12 19:28:57.237 xxxTest[12013:303] Server 1 connected
    2012-09-12 19:28:57.401 xxxTest[12013:303] libssh2_channel_read returned -37
    2012-09-12 19:28:57.496 xxxTest[12013:303] libssh2_channel_read returned 0
    2012-09-12 19:28:57.497 xxxTest[12013:303]
    EXIT: 0 bytecount: 105
    2012-09-12 19:28:57.498 xxxTest[12013:303] (null)
    2012-09-12 19:28:57.498 xxxTest[12013:303] all done

    Any ideas on how I get the output of the command?

  8. Julian
    September 13, 2012

    I tried using the wrapper in my iOS project.

    My attempt was to connect to a Mac OS X Lion server using password authentication.

    Every time I try to connect to the server I’m getting “Authentication by password failed for user”.

    Using the Terminal app, I don’t have problems to login to the server.

    How can I fix this issue?!

  9. Julian
    September 13, 2012

    It’s me again.

    I did a little bit of research and found out that my SSH host does not support password authentication (configuration disallowed).
    I changed the configuration and now it works.

    BUT: I can’t change the configuration an my web server. So my question is: How does Terminal do that?
    I mean it can still authenticate with password when the option is disabled in configuration file.

    Thanks for help

  10. Jan Galler
    September 20, 2012

    It’s me again! And I’ve a question about »NMSSH: Unable to open SCP session«…
    So, I’m doing the following:
    1. create a file
    2. download the file
    3. delete the file

    My solution works part by part, but I get »NMSSH: Unable to open SCP session« if I try to download the file after automatically generate it. If I do a manual download request, the file will be downloaded successfully! And I’m really sure the file paths are correct. The generate command works fine every time! The following link contains a screenshot of the download function:

    What could be the problem? Thank you so much!

  11. dan
    September 24, 2012

    Can’t really help you here.. NMSSH is a wrapper written by someone else, that I wasn’t aware of.

  12. dan
    September 24, 2012

    Julian.. the newer release of my sshwrapper supports password and keyboard authentication, so you should be fine now..


  13. Andi
    October 24, 2012


    thank you for the awesome wrapper. I have only 1 problem. When i putt in the ip is working fine. If I request whit a its not working :/


  14. dan
    October 26, 2012

    Download the release from GitHub I added code to do DNS resolution..


  15. Andi
    October 26, 2012


    can’t find the updated files. Can you give me a link?


  16. t.o.
    January 17, 2013

    Hey this lib works great for making calls through ssh UNLESS you need a return value.

    Context: Making calls to a bash script that returns a “/” separated list never responds consistently. Ended up reverting to NSTask and it works flawlessly (if you have ssh keys for the box)

    Where I was not relying on a response, everything that I called remotely with this lib also works flawlessly.

    Thanks again for the code!

  17. Nelson
    June 12, 2013

    Good job. There is a very good tut/example, but how can i flush the output during a large bash script?
    When I execute a test script with a 5s loop, the App hangs 5 seconds and then the output of the last line is shown.

    Best regards

  18. KZL
    October 30, 2013

    I create correctly my frameworks and libssh2 library, but now how can I use this to my cocoa project to enable a ssh connection ?
    I add the SSH Wrapper into my project, but what I do with libssh2 to add it to my project ?

    Thank you 🙂

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>