承接 pagemachine/authorized-keys 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pagemachine/authorized-keys

最新稳定版本:2.2.0

Composer 安装命令:

composer require pagemachine/authorized-keys

包简介

Read, edit and write the SSH authorized_keys file

README 文档

README

Read, edit and write the SSH authorized_keys file.

Installation

composer require pagemachine/authorized-keys

Usage

To access the authorized_keys file an instance of Pagemachine\AuthorizedKeys\AuthorizedKeys must be created, either directly passing the file content to the constructor or using the static fromFile() method:

$path = '/home/foo/.ssh/authorized_keys';
$authorizedKeys = AuthorizedKeys::fromFile($path);

You can easily iterate all keys in the file, comments and empty lines will be skipped:

foreach ($authorizedKeys as $key) {
    // Do something with $key
}

To add a key, create an instance of Pagemachine\AuthorizedKeys\PublicKey and add it to the file:

// ... load $authorizedKeys ...
$key = new PublicKey('ssh-rsa AAA...');
$authorizedKeys->addKey($key);

Notice that each key is only added once, if you add it again, only its options, type and comment are updated accordingly. Thus it's safe to call this method in any case to ensure keys are present.

To remove a key, wrap it in PublicKey and remove it from the file:

// ... load $authorizedKeys ...
$key = new PublicKey('ssh-rsa AAA...');
$authorizedKeys->removeKey($key);

To close things off, write back the file, comments and empty lines will be left unchanged:

$authorizedKeys->toFile($path);

The permissions of the file will be changed to 0600, namely readable and writable by the owner but nobody else.

Testing

All tests can be executed with the shipped Docker Compose definition:

docker compose run --rm app composer build

统计信息

  • 总下载量: 59.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2017-02-08