{"action":"created","issue":{"url":"https://api.github.com/repos/phpseclib/phpseclib/issues/653","labels_url":"https://api.github.com/repos/phpseclib/phpseclib/issues/653/labels{/name}","comments_url":"https://api.github.com/repos/phpseclib/phpseclib/issues/653/comments","events_url":"https://api.github.com/repos/phpseclib/phpseclib/issues/653/events","html_url":"https://github.com/phpseclib/phpseclib/issues/653","id":66010635,"number":653,"title":"Need your help. ","user":{"login":"superstartickets","id":11777121,"avatar_url":"https://avatars.githubusercontent.com/u/11777121?v=3","gravatar_id":"","url":"https://api.github.com/users/superstartickets","html_url":"https://github.com/superstartickets","followers_url":"https://api.github.com/users/superstartickets/followers","following_url":"https://api.github.com/users/superstartickets/following{/other_user}","gists_url":"https://api.github.com/users/superstartickets/gists{/gist_id}","starred_url":"https://api.github.com/users/superstartickets/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superstartickets/subscriptions","organizations_url":"https://api.github.com/users/superstartickets/orgs","repos_url":"https://api.github.com/users/superstartickets/repos","events_url":"https://api.github.com/users/superstartickets/events{/privacy}","received_events_url":"https://api.github.com/users/superstartickets/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phpseclib/phpseclib/labels/support","name":"support","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-02T21:00:29Z","updated_at":"2015-04-03T04:01:24Z","closed_at":null,"body":"Hello,\r\n\r\nThanks for contributing your phpseclib script to the community. \r\n\r\nI'm having a little difficulty on using the script on a second level security teir. \r\n\r\n1.) It is important to know im able to ssh tunneling through putty and use mysql to forward to local port 3306 . my goal is not to use putty but to use php instead.\r\n\r\n\r\n<?php\r\n//the code below works. and successfully logins to the server ssh using a private key\r\nset_include_path(get_include_path(). PATH_SEPARATOR. 'phpseclib');\r\n\r\ninclude('phpseclib/Net/SSH2.php');\r\ninclude('phpseclib/Crpt/RSA.php');\r\n\r\n$ssh = new Net_SSH('ourwebsite.com');\r\n$key = new Crypt_RSA();\r\n$key->setPassword('ourpassword');\r\n$key->loadKey(file_get_contents('ourprivatekey.ppk'));\r\nif (!$ssh->login('ourusername',$key)){\r\nexit('Login Failed');\r\n}\r\n\r\necho $ssh->exec('pwd');\r\necho $ssh->exec('Is -la');\r\n?>\r\n\r\n// every works so far.. now the part that does not work \r\n// i want to port forward mysql\r\n\r\n<?php\r\n\r\n\r\n$ssh->exec('ssh -l 3307:localhost:3306 ourwebsite.com sleep 60');\r\n// ssh replies Permission denied (publickey).\r\n\r\n$db = mysqli_connect (\"127.0.0.1\", \"ourusername\",\"ourpassword\",\"ourdatabasename\",3307);\r\n// no connection could be made because the target machine actively refused it.\r\n\r\n?>\r\n\r\nssh replies permission denied publickey must not match.  This is not the case before we get to the port forward execution Im assuming to set the port forwarding via i need to include the public key? I'm at a point that I need assitance, what am i doing wrong. Can you do any adjustments to the code to make it functional  thank you.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/phpseclib/phpseclib/issues/comments/89154815","html_url":"https://github.com/phpseclib/phpseclib/issues/653#issuecomment-89154815","issue_url":"https://api.github.com/repos/phpseclib/phpseclib/issues/653","id":89154815,"user":{"login":"terrafrost","id":214474,"avatar_url":"https://avatars.githubusercontent.com/u/214474?v=3","gravatar_id":"","url":"https://api.github.com/users/terrafrost","html_url":"https://github.com/terrafrost","followers_url":"https://api.github.com/users/terrafrost/followers","following_url":"https://api.github.com/users/terrafrost/following{/other_user}","gists_url":"https://api.github.com/users/terrafrost/gists{/gist_id}","starred_url":"https://api.github.com/users/terrafrost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terrafrost/subscriptions","organizations_url":"https://api.github.com/users/terrafrost/orgs","repos_url":"https://api.github.com/users/terrafrost/repos","events_url":"https://api.github.com/users/terrafrost/events{/privacy}","received_events_url":"https://api.github.com/users/terrafrost/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T04:01:24Z","updated_at":"2015-04-03T04:01:24Z","body":"```php\r\n$ssh->exec('ssh -l 3307:localhost:3306 ourwebsite.com sleep 60');\r\n```\r\nPer `man ssh` I think what you want to do is `ssh -L`. I also note that you're not specifying a username or key in that command. If you're logging in as ourusername (ie. the same user you SSH'd into the box initially with) I guess the lack of a username doesn't matter but there's still the matter of the key. Is it in your id_rsa file on ourwebsite.com? Otherwise that command won't work.\r\n\r\nFinally, unless you're SSH'ing into ourwebsite.com from ourwebsite.com then presumably the 127.0.0.1:3307 mysql \"server\" will be on ourwebsite.com and not the machine you're doing the SSH'ing from.\r\n\r\n"}}