web-dev-qa-db-fra.com

Comment ajouter une clé SSH à une instance VPS de Google Compute Cloud?

Comment ajouter une clé SSH à une instance de cloud?

J'ai essayé d'ajouter des clés manuellement, mais je ne pouvais pas me connecter. Voici ce que j'ai essayé:

thufir@mordor:~$ 
thufir@mordor:~$ gcloud compute config-ssh
WARNING: The private SSH key file for Google Compute Engine does not exist.
WARNING: You do not have an SSH key for Google Compute Engine.
WARNING: [/usr/bin/ssh-keygen] will be executed to generate a key.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/thufir/.ssh/google_compute_engine.
Your public key has been saved in /home/thufir/.ssh/google_compute_engine.pub.
The key fingerprint is:
SHA256:ioreurewiopruweoiprwe thufir@mordor
The key's randomart image is:
+---[RSA 2048]----+
.......
|                 |
|                 |
+----[SHA256]-----+

Updated [https://www.googleapis.com/compute/v1/projects/<project>].
You should now be able to use ssh/scp with your instances.
For example, try running:

  $ ssh <instance>.<location>.<project>

thufir@mordor:~$ 
thufir@mordor:~$ ssh <instance>.<location>.<project>
The authenticity of Host 'compute.<####> (<ip address>)' can't be established.
ECDSA key fingerprint is SHA256:<fingerprint?>.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'compute.<####>' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-31-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

$ 
$ 
$ whoami
thufir
$ pwd
/home/thufir
$ exit
Connection to <ip address> closed.
thufir@mordor:~$ 
1
Thufir

Probablement une réponse trop tardive, mais la voici

ssh-keygen -t rsa -f ~/.ssh/google_compute_engine -C <service-account>

Ensuite

gcloud compute ssh <service-account> --command="bash xxxxxx"
3
alschytt

Vous n'avez pas besoin de l'ajouter manuellement dans le dossier de l'utilisateur. Google Cloud l'ajoute automatiquement chaque fois que vous essayez de vous connecter à votre ordinateur virtuel. Pour ajouter définitivement une clé SSH dans une instance VM, vous pouvez ajouter votre clé publique dans les métadonnées du menu. Le processus étape par étape est expliqué ici.

0
Vipin Yadav