How do I add a SSH key to Google Cloud Compute Engine VM Linux instance?
I have a Linux VM instance running in Google Cloud Platform.
I tried to copy my public key to ~/.ssh/authorized_keys and I can successfully SSH to my VM.
But sometimes ~/.ssh/authorized_keys is flushed and I have to copy the public key again.
It is really a pain to add public key every time.
How do I add a public key permanently?
ubuntu google-cloud-platform google-compute-engine
add a comment |
I have a Linux VM instance running in Google Cloud Platform.
I tried to copy my public key to ~/.ssh/authorized_keys and I can successfully SSH to my VM.
But sometimes ~/.ssh/authorized_keys is flushed and I have to copy the public key again.
It is really a pain to add public key every time.
How do I add a public key permanently?
ubuntu google-cloud-platform google-compute-engine
Are other files in your home dir disappearing as well (is the homedir wiped)?
– Dan Cornilescu
Nov 23 '18 at 15:51
No, they are just the same.
– Valeri
Nov 26 '18 at 5:21
add a comment |
I have a Linux VM instance running in Google Cloud Platform.
I tried to copy my public key to ~/.ssh/authorized_keys and I can successfully SSH to my VM.
But sometimes ~/.ssh/authorized_keys is flushed and I have to copy the public key again.
It is really a pain to add public key every time.
How do I add a public key permanently?
ubuntu google-cloud-platform google-compute-engine
I have a Linux VM instance running in Google Cloud Platform.
I tried to copy my public key to ~/.ssh/authorized_keys and I can successfully SSH to my VM.
But sometimes ~/.ssh/authorized_keys is flushed and I have to copy the public key again.
It is really a pain to add public key every time.
How do I add a public key permanently?
ubuntu google-cloud-platform google-compute-engine
ubuntu google-cloud-platform google-compute-engine
edited Nov 24 '18 at 10:44
Maxim
1,506210
1,506210
asked Nov 23 '18 at 12:46
ValeriValeri
14511
14511
Are other files in your home dir disappearing as well (is the homedir wiped)?
– Dan Cornilescu
Nov 23 '18 at 15:51
No, they are just the same.
– Valeri
Nov 26 '18 at 5:21
add a comment |
Are other files in your home dir disappearing as well (is the homedir wiped)?
– Dan Cornilescu
Nov 23 '18 at 15:51
No, they are just the same.
– Valeri
Nov 26 '18 at 5:21
Are other files in your home dir disappearing as well (is the homedir wiped)?
– Dan Cornilescu
Nov 23 '18 at 15:51
Are other files in your home dir disappearing as well (is the homedir wiped)?
– Dan Cornilescu
Nov 23 '18 at 15:51
No, they are just the same.
– Valeri
Nov 26 '18 at 5:21
No, they are just the same.
– Valeri
Nov 26 '18 at 5:21
add a comment |
2 Answers
2
active
oldest
votes
This ~/.ssh/authorized_keys takes the ssh keys from the metadata. It best you keep your ssh public keys in the metadata as mentioned here and there’s also a stack discussion here
add a comment |
One possible reason for which the file would "disappear" would be that every time the instance is reloaded it is reloaded from the same VM image, which doesn't contain the file. Check if the occurences are correlated with the instance reloading and if other files in your home dir disappear as well, if they do that's likely the culprit. If so I can see a couple of possible approaches:
include the
~/.ssh/authorized_keysfile (and, of course, your user and home directory configurations) into a custom VM image that you could then use to boot your instances fromconfigure your home directory on a persistent disk which would survive across instance reloads
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446990%2fhow-do-i-add-a-ssh-key-to-google-cloud-compute-engine-vm-linux-instance%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This ~/.ssh/authorized_keys takes the ssh keys from the metadata. It best you keep your ssh public keys in the metadata as mentioned here and there’s also a stack discussion here
add a comment |
This ~/.ssh/authorized_keys takes the ssh keys from the metadata. It best you keep your ssh public keys in the metadata as mentioned here and there’s also a stack discussion here
add a comment |
This ~/.ssh/authorized_keys takes the ssh keys from the metadata. It best you keep your ssh public keys in the metadata as mentioned here and there’s also a stack discussion here
This ~/.ssh/authorized_keys takes the ssh keys from the metadata. It best you keep your ssh public keys in the metadata as mentioned here and there’s also a stack discussion here
answered Nov 23 '18 at 18:54
AdebisiAdebisi
444
444
add a comment |
add a comment |
One possible reason for which the file would "disappear" would be that every time the instance is reloaded it is reloaded from the same VM image, which doesn't contain the file. Check if the occurences are correlated with the instance reloading and if other files in your home dir disappear as well, if they do that's likely the culprit. If so I can see a couple of possible approaches:
include the
~/.ssh/authorized_keysfile (and, of course, your user and home directory configurations) into a custom VM image that you could then use to boot your instances fromconfigure your home directory on a persistent disk which would survive across instance reloads
add a comment |
One possible reason for which the file would "disappear" would be that every time the instance is reloaded it is reloaded from the same VM image, which doesn't contain the file. Check if the occurences are correlated with the instance reloading and if other files in your home dir disappear as well, if they do that's likely the culprit. If so I can see a couple of possible approaches:
include the
~/.ssh/authorized_keysfile (and, of course, your user and home directory configurations) into a custom VM image that you could then use to boot your instances fromconfigure your home directory on a persistent disk which would survive across instance reloads
add a comment |
One possible reason for which the file would "disappear" would be that every time the instance is reloaded it is reloaded from the same VM image, which doesn't contain the file. Check if the occurences are correlated with the instance reloading and if other files in your home dir disappear as well, if they do that's likely the culprit. If so I can see a couple of possible approaches:
include the
~/.ssh/authorized_keysfile (and, of course, your user and home directory configurations) into a custom VM image that you could then use to boot your instances fromconfigure your home directory on a persistent disk which would survive across instance reloads
One possible reason for which the file would "disappear" would be that every time the instance is reloaded it is reloaded from the same VM image, which doesn't contain the file. Check if the occurences are correlated with the instance reloading and if other files in your home dir disappear as well, if they do that's likely the culprit. If so I can see a couple of possible approaches:
include the
~/.ssh/authorized_keysfile (and, of course, your user and home directory configurations) into a custom VM image that you could then use to boot your instances fromconfigure your home directory on a persistent disk which would survive across instance reloads
edited Nov 25 '18 at 0:10
answered Nov 24 '18 at 19:26
Dan CornilescuDan Cornilescu
27.8k113162
27.8k113162
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446990%2fhow-do-i-add-a-ssh-key-to-google-cloud-compute-engine-vm-linux-instance%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are other files in your home dir disappearing as well (is the homedir wiped)?
– Dan Cornilescu
Nov 23 '18 at 15:51
No, they are just the same.
– Valeri
Nov 26 '18 at 5:21