GitTips » Historique » Version 4
Geoffroy Desvernay, 25/06/2014 17:04
1 | 1 | Geoffroy Desvernay | h1. Trucs et astuces pour git |
---|---|---|---|
2 | 1 | Geoffroy Desvernay | |
3 | 1 | Geoffroy Desvernay | {{>toc}} |
4 | 1 | Geoffroy Desvernay | |
5 | 1 | Geoffroy Desvernay | h2. Utiliser ma clé ssh depuis une machine distante |
6 | 1 | Geoffroy Desvernay | |
7 | 1 | Geoffroy Desvernay | # Je dois avoir un 'ssh-agent' qui tourne avec ma session (c'est souvent le cas par défaut sous linux) |
8 | 1 | Geoffroy Desvernay | Pour vérifier: <pre>echo $SSH_AUTH_SOCK</pre> |
9 | 1 | Geoffroy Desvernay | # mon client ssh doit faire suivre l'agent au serveur, pour ça il faut taper 'ssh -A' ou avoir, dans /etc/ssh/ssh_config ou ~/.ssh/config |
10 | 1 | Geoffroy Desvernay | <pre> |
11 | 1 | Geoffroy Desvernay | ForwardAgent yes |
12 | 1 | Geoffroy Desvernay | </pre> |
13 | 1 | Geoffroy Desvernay | |
14 | 1 | Geoffroy Desvernay | h3. Pour OSX, utiliser |
15 | 1 | Geoffroy Desvernay | |
16 | 1 | Geoffroy Desvernay | <pre>ssh-add -K ~/.ssh/id_rsa</pre> |
17 | 1 | Geoffroy Desvernay | |
18 | 1 | Geoffroy Desvernay | h3. Pour windows, http://blog.killtheradio.net/how-tos/ssh-agent-on-cygwin/ |
19 | 1 | Geoffroy Desvernay | |
20 | 1 | Geoffroy Desvernay | h2. utiliser une cle de déploiement sur un serveur pour récupérer le code |
21 | 1 | Geoffroy Desvernay | |
22 | 1 | Geoffroy Desvernay | # Créer une clé ssh sur le serveur |
23 | 1 | Geoffroy Desvernay | <pre> |
24 | 1 | Geoffroy Desvernay | ssh-keygen -C "Deploiement sur $(hostname -s)" -f ~/.ssh/id_rsa_deploy -N '' |
25 | 1 | Geoffroy Desvernay | </pre> |
26 | 1 | Geoffroy Desvernay | # L'ajouter dans la forge en tant que 'pièce d'identité de déploiement' (deployment key) |
27 | 1 | Geoffroy Desvernay | Projet->Configuration->Dépôt->Ajouter une pièce d'identité de déploiement |
28 | 1 | Geoffroy Desvernay | # configurer mon serveur pour l'utiliser |
29 | 1 | Geoffroy Desvernay | dans le fichier ~/.ssh/config de l'utilisateur sur le serveur: |
30 | 1 | Geoffroy Desvernay | <pre> |
31 | 1 | Geoffroy Desvernay | Host git.centrale-marseille.fr |
32 | 1 | Geoffroy Desvernay | IdentityFile ~/.ssh/id_rsa_deploy |
33 | 1 | Geoffroy Desvernay | </pre> |
34 | 1 | Geoffroy Desvernay | |
35 | 2 | Geoffroy Desvernay | |
36 | 4 | Geoffroy Desvernay | h2. faire des commits avec sa cle depuis une machine distante |
37 | 4 | Geoffroy Desvernay | |
38 | 4 | Geoffroy Desvernay | Exemple: sur une machine serveur je veux récupérer automatiquement mon dépôt GIT, mais je veux pouvoir commiter en utilisant ma clé (et mon identité): |
39 | 1 | Geoffroy Desvernay | |
40 | 1 | Geoffroy Desvernay | # Je me crée (sur ma machine) des variables GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL : |
41 | 1 | Geoffroy Desvernay | <pre> |
42 | 1 | Geoffroy Desvernay | GIT_COMMITTER_EMAIL="moi@centrale-marseille.fr" |
43 | 1 | Geoffroy Desvernay | GIT_COMMITTER_NAME="Prénom Nom" |
44 | 1 | Geoffroy Desvernay | GIT_AUTHOR_EMAIL=$GIT_COMMITTER_EMAIL |
45 | 3 | Geoffroy Desvernay | GIT_AUTHOR_NAME=$GIT_COMMITTER_NAME |
46 | 1 | Geoffroy Desvernay | export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME |
47 | 1 | Geoffroy Desvernay | </pre> |
48 | 1 | Geoffroy Desvernay | # Dans mon fichier ~/.ssh/config, j'ajoute: |
49 | 1 | Geoffroy Desvernay | <pre> |
50 | 1 | Geoffroy Desvernay | Host * |
51 | 1 | Geoffroy Desvernay | SendEnv LANG LC_* GIT_* |
52 | 1 | Geoffroy Desvernay | </pre> |
53 | 1 | Geoffroy Desvernay | # sur le serveur (celui qui a la clé de déploiement), il faut dans /etc/ssh/sshd_config: |
54 | 1 | Geoffroy Desvernay | <pre> |
55 | 1 | Geoffroy Desvernay | AcceptEnv GIT_* |
56 | 1 | Geoffroy Desvernay | </pre> |
57 | 2 | Geoffroy Desvernay | # Re-connectez-vous sur le serveur, et vérifiez que vos variables sont bien là: |
58 | 2 | Geoffroy Desvernay | <pre> |
59 | 2 | Geoffroy Desvernay | echo $SSH_AUTH_SOCK $GIT_COMMITTER_EMAIL |
60 | 2 | Geoffroy Desvernay | </pre> |