0

I have a VM in Google Compute Engine that I want to start and stop daily - I have already written Cloud Functions for this. When the VM starts, I want it to run a startup script. In the bash startup script, I first need to pull data from git - Cloud Source Repository. This causes it to crash:

Error: Permission denied (publickey)

The startup script looks like this:

#!/bin/bash 
cd /home/my_home_directory/git_repo
git pull;
cd some_directory_in_repo
python3 some_script.py;
shutdown -h now;

The VM has its own service account, which, as far as I know, runs the script. What I basically want, is to run the script with a "user" - service account - that does not have a home directory on the VM (the service account has the necessary permissions for accessing the repository, though). I also set up SSH key for the service account, then I registered the public key on my user profile and this works when I execute the script under my user.

Is there a solution for this, other than run the script under my user (which works, as I said), please?

Note: If I execute the startup script like the one below, it also works.

#!/bin/bash 
cd /home/my_home_directory/git_repo
sudo -u my_username bash -c \
'git pull;
cd some_directory_in_repo
python3 some_script.py;
shutdown -h now;'

Thanks

  • The service account is not related to the startup script. The VM will start up and run without a service account. Which repository are you using? How is authorization configured? Edit your question with more details. One important detail, startup scripts do not run as a normal user. Therefore anything that you configured in your home directory is meaningless. Typically the startup script runs as the `root` user. – John Hanley Mar 24 '20 at 19:49
  • You can create a user account without a home directory by entering the following: useradd -M [username] or useradd --no-create-home [username]. This will create a user, but not create the home directory. From here, you can try to add the public key to the newly created user. – Ashik Mahbub Mar 24 '20 at 22:32

0 Answers0