Reputation: 33
I am using a GCP compute engine(Ubuntu 18.04) for my flask app. I had no issues setting up the Flask and Python environment. My issue is when I SSH into the instance a new user is created with the user name of the computer that I am using. When I SSH from a different system or one of my colleagues try to log in, a new user is getting created with the username of the computer that has been used. I don't want this behavior. I want to log into a single user all the time.
Upvotes: 0
Views: 2455
Reputation: 21
You can create an ssh key locally (with any username), and then add it's public SSH key to a GCP project or instance(s) via the console. Just place ssh files on each computer that you plan on using to access the VM, and this will use only the username you've specified during the SSH key creation.
For instructions on how to do this for Windows and/or the gcloud CLI, or for adding the public SSH key to a project or instance, follow the Google Cloud documentation guide Managing SSH keys in metadata
On Linux or MacOS workstations, you can generate a key by using the ssh-keygen tool.
Open a terminal on your workstation and use the ssh-keygen command to generate a new key. Specify the -C flag to add a comment with your username.
ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]
where:
This command generates a private SSH key file and a matching public
SSH key with the following structure:
ssh-rsa [KEY_VALUE] [USERNAME]
where:
Restrict access to your private key so that only you can read it and nobody can write to it.
chmod 400 ~/.ssh/[KEY_FILENAME]
where:
Afterwards, locate the public SSH keys that you made and/or any existing public SSH keys that you want to add to a project or instance. Add those keys to the GCP project or instance(s) by editing the respective metadata as described in the Managing SSH keys in metadata guide.
You can now SSH into those GCP resources from a machine with the private SSH keys you created.
ssh [USERNAME]@[IP_ADDRESS]
Where:
Upvotes: 0
Reputation: 1917
Have you considered using gcloud compute ssh
cli? Using this you can override the user you are logging in as by providing user@ see user argument.
[USER@]INSTANCE
Specifies the instance to SSH into.
USER specifies the username with which to SSH. If omitted, the user login name is used.
INSTANCE specifies the name of the virtual machine instance to SSH into.
see: https://cloud.google.com/sdk/gcloud/reference/compute/ssh
Also see this thread which seems to explain how you can achieve this with standard ssh means:
https://unix.stackexchange.com/questions/404116/how-to-login-with-ssh-as-a-specific-user
Upvotes: 1