Skip to content

Commit eedd819

Browse files
committed
Add SSH2 connection sample
1 parent 52639c4 commit eedd819

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ before_script:
99
- lsb_release -a
1010
- sudo apt-get update && sudo apt-get install libssh2-1 -y
1111
- echo "extension=ssh2.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
12+
- ssh-keygen -N '' -f ~/.ssh/id_rsa
13+
- cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
1214

13-
script: php -m | grep ssh2
15+
script: php sample_connect.php

sample_connect.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
$connection = ssh2_connect('localhost', 22, ['hostkey'=>'ssh-rsa']);
4+
5+
if (ssh2_auth_pubkey_file($connection, 'root',
6+
'/home/travis/.ssh/id_rsa.pub',
7+
'/home/travis/.ssh/id_rsa')) {
8+
echo "Public Key Authentication Successful\n";
9+
} else {
10+
die('Public Key Authentication Failed');
11+
}

0 commit comments

Comments
 (0)