Generates SSH keys from Gradle

Clone this repo:
  1. eec858a test: reuse code by Basil Peace · 5 years ago master v1.0.0
  2. 7e5c235 chore: update description and set tags project-wide by Basil Peace · 5 years ago
  3. 9802206 chore: update build tools by Basil Peace · 5 years ago
  4. 9067fbe chore: avoid task creation in build.gradle by Basil Peace · 5 years ago
  5. 726ccb5 chore: reorder code according to standard layout by Basil Peace · 5 years ago


This plugin provides Gradle ability to generate SSH keys.

It uses JSch Java library, no installation of extra tools is required.


plugins { id 'org.fidata.keygen' } keygen { keyType = RSA keySize = 4096 } task('generateSSHKey', type: GenerateSSHKeyTask) { privateKeyFile = new File(buildDir, 'ssh_key') email = '' }

This task, when run, would produce ssh_key and files in build directory.

keyType and keySize properties can be set per-task via its properties. Otherwise, project-wide values from keygen extension are used.

Since keys can't be restored, to prevent key loss task will run only if either private or public key file doesn't exist. If you want to regenerate key (including when you changed desired key properties) you should clean them manually beforehand.

Other types of keys could be supported in the future.


  • Gradle >= 4.4
  • Developed and tested with JDK 8

Copyright © 2018 Basil Peace

This file is part of gradle-keygen-plugin.

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.