mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-22 03:02:20 +00:00
generate ssh keys command
This commit is contained in:
parent
8bf1cc141e
commit
974af959f1
33
app/Console/Commands/GenerateKeysCommand.php
Normal file
33
app/Console/Commands/GenerateKeysCommand.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
|
||||||
|
class GenerateKeysCommand extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'ssh-key:generate {--force}';
|
||||||
|
|
||||||
|
protected $description = 'Generate keys';
|
||||||
|
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$privateKeyPath = storage_path('ssh-private.pem');
|
||||||
|
$publicKeyPath = storage_path('ssh-public.key');
|
||||||
|
|
||||||
|
if (File::exists($privateKeyPath) && File::exists($publicKeyPath) && !$this->option('force')) {
|
||||||
|
$this->error('Keys already exist. Use --force to overwrite.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
exec('openssl genpkey -algorithm RSA -out ' . $privateKeyPath);
|
||||||
|
exec('chmod 600 ' . $privateKeyPath);
|
||||||
|
exec('ssh-keygen -y -f ' . $privateKeyPath . ' > ' . $publicKeyPath);
|
||||||
|
exec('chown -R ' . get_current_user() . ':' . get_current_user() . ' ' . $privateKeyPath);
|
||||||
|
exec('chown -R ' . get_current_user() . ':' . get_current_user() . ' ' . $publicKeyPath);
|
||||||
|
|
||||||
|
$this->info('Keys generated successfully.');
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
use Filament\Notifications\Actions\Action;
|
use Filament\Notifications\Actions\Action;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
function generate_public_key($privateKeyPath, $publicKeyPath): void
|
function generate_public_key($privateKeyPath, $publicKeyPath): void
|
||||||
@ -56,6 +57,10 @@ function convert_time_format($string): string
|
|||||||
|
|
||||||
function get_public_key_content(): string
|
function get_public_key_content(): string
|
||||||
{
|
{
|
||||||
|
if (! file_exists(storage_path(config('core.ssh_public_key_name')))) {
|
||||||
|
Artisan::call('ssh-key:generate --force');
|
||||||
|
}
|
||||||
|
|
||||||
return str(file_get_contents(storage_path(config('core.ssh_public_key_name'))))
|
return str(file_get_contents(storage_path(config('core.ssh_public_key_name'))))
|
||||||
->replace("\n", '')
|
->replace("\n", '')
|
||||||
->toString();
|
->toString();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user