Skip to content

Commit 9476a90

Browse files
committed
Merge branch 'develop'
2 parents 30a4292 + f61479d commit 9476a90

File tree

11 files changed

+556
-2
lines changed

11 files changed

+556
-2
lines changed

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 4
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
15+
[*.md]
16+
trim_trailing_whitespace = false
17+
18+
[*.yml]
19+
indent_size = 2

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
client*/
2+
personal/
3+
work/
4+
node_modules/
5+
.DS_Store
6+
.idea
7+
.vscode
8+
known_hosts*
9+
id_rsa*
10+
package-lock.json
11+
yarn.lock
12+
loki.txt

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx --no -- commitlint --edit

.husky/post-merge

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm i

.husky/post-rewrite

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm i

README.es.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# SSH Key Manager
2+
3+
Crea y cambia entre múltiples claves SSH fácilmente.
4+
5+
### El problema
6+
7+
Herramientas como GitHub, GitLab y Bitbucket utilizan claves SSH para autenticar a los usuarios y no permiten el uso de la misma clave para diferentes cuentas.
8+
9+
Si utilizas tu ordenador para trabajar y también para proyectos personales, es probable que necesites múltiples claves SSH para diferentes cuentas (por ejemplo, una para el trabajo, otra para un cliente, otra para proyectos personales). Manejar estas claves manualmente puede ser tedioso.
10+
11+
Este script simplifica el proceso, permitiendo crear y cambiar rápidamente entre diferentes claves SSH.
12+
13+
### Requisitos
14+
15+
- Sistema operativo Unix (Linux, macOS)
16+
- Conocimientos básicos de scripting y uso de la línea de comandos (opcional)
17+
- Git instalado para clonar el repositorio
18+
19+
### Instalación
20+
21+
1. Clonar el repositorio:
22+
```bash
23+
cd ~
24+
git clone https://github.com/jjpeleato/bash-ssh-key-manager.git ssh-key-manager
25+
```
26+
2. Copia los scripts (`initialize.sh` y `environment.sh`) en el directorio `.ssh`:
27+
```bash
28+
cd ~/ssh-key-manager
29+
cp *.sh ~/.ssh/
30+
```
31+
3. Dar permisos de ejecución a los scripts:
32+
```bash
33+
cd ~
34+
chmod +x .ssh/initialize.sh
35+
chmod +x .ssh/environment.sh
36+
```
37+
4. Eliminar el repositorio clonado:
38+
```bash
39+
cd ~
40+
rm -rf ssh-key-manager
41+
```
42+
5. ¡Fin y feliz uso!
43+
44+
### Uso
45+
46+
1. Ejecuta el script `initialize.sh` para crear las claves SSH que necesites. Sigue las instrucciones en pantalla, es muy fácil. Recuerda añadir una `passphrase` segura para cada clave.
47+
```bash
48+
cd ~/.ssh
49+
sh initialize.sh
50+
```
51+
2. Cada vez que necesites cambiar de clave SSH, ejecuta el script `environment.sh` y selecciona la clave deseada.
52+
```bash
53+
cd ~/.ssh
54+
sh environment.sh
55+
```
56+
3. ¡Listo! Ahora cambia entre tus claves SSH fácilmente.
57+
58+
**Nota:** No olvides añadir las claves públicas generadas a las plataformas correspondientes (GitHub, GitLab, Bitbucket, etc.).
59+
60+
### Aclaraciones
61+
62+
- El script `initialize.sh` crea un archivo llamado `loki.txt` en el directorio `~/.ssh` que contiene un resumen de las claves creadas. Es importante no borrar este archivo a menos que desees reiniciar el proceso.
63+
- Las claves SSH se almacenan en el directorio `~/.ssh` dentro de subdirectorios nombrados según la cuenta (por ejemplo, `work`, `personal`).
64+
- Las claves creadas usan el formato `ed25519`, que es más seguro y eficiente que el formato RSA tradicional.
65+
- Si creas para FileZilla un archivo `.ppk` a partir de tu clave, llama al archivo de la siguiente forma `id_rsa_filezilla.ppk` y guárdalo en el mismo subdirectorio que la clave original. El script `environment.sh` lo detectará automáticamente.
66+
67+
### Migración desde clave SSH existente
68+
69+
Si ya tienes una clave SSH existente y deseas integrarla en este sistema, sigue estos pasos:
70+
71+
1. Mueve tu clave SSH en `~/.ssh` dentro de un subdirectorio (por ejemplo, `~/.ssh/work`, `~/.ssh/personal`).
72+
2. Si existe. Elimina el archivo `~/.ssh/loki.txt`.
73+
3. Ejecuta el script `initialize.sh` y en el proceso de creación de claves, utiliza el mismo nombre que el nombre del subdirectorio donde has movido tu clave. El script lo detectará y lo tendrá en cuenta automáticamente.
74+
4. Sigue las instrucciones en pantalla para completar el proceso.
75+
76+
### Método nativo (alternativa)
77+
78+
Usa el script `initialize.sh` para generar tus claves SSH y, a continuación, crea o edita el archivo `~/.ssh/config` con las configuraciones necesarias.
79+
80+
A continuación, un ejemplo de configuración para dos cuentas de GitHub (trabajo y personal):
81+
82+
```text
83+
# Work account
84+
Host github-work
85+
HostName github.com
86+
User git
87+
IdentityFile ~/.ssh/work/id_rsa
88+
IdentitiesOnly yes
89+
90+
# Personal account
91+
Host github-personal
92+
HostName github.com
93+
User git
94+
IdentityFile ~/.ssh/personal/id_rsa
95+
IdentitiesOnly yes
96+
```
97+
98+
**Nota:** Asegúrate de reemplazar en la URL de tu repositorio remoto `github.com` por `github-work` o `github-personal` según corresponda.
99+
100+
```bash
101+
git remote -v
102+
git remote set-url origin git@github-personal:jjpeleato/bash-ssh-key-manager.git
103+
```
104+
105+
### Estructura del proyecto
106+
107+
```
108+
ssh-key-manager/
109+
├── .husky/
110+
│ ├── commit-msg
111+
│ ├── post-merge
112+
│ └── post-rewrite
113+
├── .editorconfig
114+
├── .gitignore
115+
├── commitlint.config.cjs
116+
├── environment.sh # Archivo principal para cambiar entre claves SSH
117+
├── initialize.sh # Archivo principal para crear claves SSH
118+
├── LICENSE
119+
├── package.json
120+
└── README.md
121+
```
122+
123+
### Contribución
124+
125+
¡Las contribuciones son bienvenidas! Por favor, haz un `fork` del repositorio y envía un `pull request` con tus cambios.
126+
127+
### Soporte
128+
129+
Para errores o funcionalidades nuevas, por favor, abre un `issue` en el repositorio o contacta conmigo directamente.
130+
131+
### Fin
132+
133+
Más información en los siguientes commits. Si es necesario.
134+
135+
Saludos, **@jjpeleato**.

README.md

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,135 @@
1-
# bash-ssh-key-manager
2-
A simple Bash script to manage and switch between multiple SSH keys with ease.
1+
# SSH Key Manager
2+
3+
Manage multiple SSH keys and switch between them easily.
4+
5+
### The problem
6+
7+
Tools like GitHub, GitLab, and Bitbucket use SSH keys to authenticate users and do not allow the same key to be used for different accounts.
8+
9+
If you use your computer for work and also for personal projects, you probably need multiple SSH keys for different accounts (for example, one for work, one for a client, and another for personal projects). Managing these keys manually can be tedious.
10+
11+
This script simplifies the process, allowing you to quickly create and switch between different SSH keys.
12+
13+
### Requirements
14+
15+
- Unix-based operating system (Linux, macOS)
16+
- Basic knowledge of bash scripting and command-line usage
17+
- Git installed for cloning the repository
18+
19+
### Installation
20+
21+
1. Clone the repository:
22+
```bash
23+
cd ~
24+
git clone https://github.com/jjpeleato/bash-ssh-key-manager.git ssh-key-manager
25+
```
26+
2. Copy the scripts (`initialize.sh` and `environment.sh`) into `.ssh` directory:
27+
```bash
28+
cd ~/ssh-key-manager
29+
cp *.sh ~/.ssh/
30+
```
31+
3. Give execution permissions to the scripts:
32+
```bash
33+
cd ~
34+
chmod +x .ssh/initialize.sh
35+
chmod +x .ssh/environment.sh
36+
```
37+
4. Remove the cloned repository:
38+
```bash
39+
cd ~
40+
rm -rf ssh-key-manager
41+
```
42+
5. End and happy use!
43+
44+
### Usage
45+
46+
1. Run the `initialize.sh` script to create the SSH keys you need. Follow the on-screen instructions, it is very easy. Remember to set a secure `passphrase` for each key.
47+
```bash
48+
cd ~/.ssh
49+
sh initialize.sh
50+
```
51+
2. Whenever you need to switch SSH keys, run the `environment.sh` script and select the desired key.
52+
```bash
53+
cd ~/.ssh
54+
sh environment.sh
55+
```
56+
3. Done! Now you can easily switch between your SSH keys.
57+
58+
**Note:** Don’t forget to add the generated public keys to the corresponding platforms (GitHub, GitLab, Bitbucket, etc).
59+
60+
### Clarifications
61+
62+
- The `initialize.sh` script creates a file called `loki.txt` in the `~/.ssh` directory, which contains a summary of the keys created. It is important not to delete this file unless you want to restart the process.
63+
- SSH keys are stored in the `~/.ssh` directory inside subdirectories named after the account (for example, `work`, `personal`).
64+
- The keys created use the `ed25519` format, which is more secure and efficient than the traditional RSA format.
65+
- If you create a `.ppk` file for FileZilla from your key, name the file `id_rsa_filezilla.ppk` and save it in the same subdirectory as the original key. The `environment.sh` script will detect it automatically.
66+
67+
### Migration from an existing SSH key
68+
69+
If you already have an existing SSH key and want to integrate it into this system, follow these steps:
70+
71+
1. Move your SSH key in `~/.ssh` into a subdirectory (for example, `~/.ssh/work`, `~/.ssh/personal`).
72+
2. If it exists, delete the file `~/.ssh/loki.txt`.
73+
3. Run the `initialize.sh` script and during the key creation process, use the same name as the subdirectory where you moved your key. The script will detect it and handle it automatically.
74+
4. Follow the on-screen instructions to complete the process.
75+
76+
### Native method (alternative)
77+
78+
Use the `initialize.sh` script to generate your SSH keys and then create or edit the `~/.ssh/config` file with the necessary configurations.
79+
80+
Below is an example configuration for two GitHub accounts (work and personal):
81+
82+
```text
83+
# Work account
84+
Host github-work
85+
HostName github.com
86+
User git
87+
IdentityFile ~/.ssh/work/id_rsa
88+
IdentitiesOnly yes
89+
90+
# Personal account
91+
Host github-personal
92+
HostName github.com
93+
User git
94+
IdentityFile ~/.ssh/personal/id_rsa
95+
IdentitiesOnly yes
96+
```
97+
98+
**Nota:** Make sure to replace `github.com` in your remote repository URL with `github-work` or `github-personal`, as appropriate.
99+
100+
```bash
101+
git remote -v
102+
git remote set-url origin git@github-personal:jjpeleato/bash-ssh-key-manager.git
103+
```
104+
105+
### Project structure
106+
107+
```
108+
ssh-key-manager/
109+
├── .husky/
110+
│ ├── commit-msg
111+
│ ├── post-merge
112+
│ └── post-rewrite
113+
├── .editorconfig
114+
├── .gitignore
115+
├── commitlint.config.cjs
116+
├── environment.sh # Main script to switch between SSH keys
117+
├── initialize.sh # Main script to create SSH keys
118+
├── LICENSE
119+
├── package.json
120+
└── README.md
121+
```
122+
123+
### Contributing
124+
125+
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
126+
127+
### Support
128+
129+
For issues or feature requests, please open an issue in the repository or contact with me directly.
130+
131+
### Finally
132+
133+
More information on the following commits. If required.
134+
135+
Grettings **@jjpeleato**.

commitlint.config.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
extends: [
3+
'@commitlint/config-conventional'
4+
]
5+
};

0 commit comments

Comments
 (0)