On OSX Terminal, I can connect to a server with SSH because terminal offers password input session.
$ ssh [email protected]
[email protected]'s password:
I wanted to make my own terminal implementation, so I
And then, pushes string ssh [email protected]
into pty master on parent process.
But by program showed me this.
$ ssh [email protected]
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
instead of password session.
What's my problem, and how can I fix it?
P.S. I know I can use expect
utility. This is just a trial to implement my own pseudo shell application.
The key to solution was using of forkpty()
function instead of posix_openpt()
function. Former one handles all hard annoying works, and gives me bi-directional master file number. I can read from and write to the file number. And the created pty device works perfectly. SSH login session works well. In contrast latter one still needs a lot of works which I never can figure out how.
I had to care about forkpty
last two parameters. I thought them was output, but actually it was input. That was the source of all the problems, and after setting them to all NULL
, it's working well now.
There is already a program which does what you want: sshpass
http://sshpass.sourceforge.net/
Since it is open source, you can examine its source to find out how it works.