Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch User (su) not working #279

Closed
shubhenduanupamdutta opened this issue Nov 4, 2023 · 6 comments · Fixed by #288
Closed

Switch User (su) not working #279

shubhenduanupamdutta opened this issue Nov 4, 2023 · 6 comments · Fixed by #288
Labels
bug Something isn't working

Comments

@shubhenduanupamdutta
Copy link

 - name: executing ubuntu instance using ssh
        uses: appleboy/ssh-action@v1.0.0
        with:
          host: ${{secrets.HOST_IP}}
          username: ubuntu
          key: ${{secrets.SSH_KEY}}
          port: 22
          script:  |
            su - ${{user}}
            whoami

I have already tried going into root mode before. But it is still not working.

@appleboy
Copy link
Owner

appleboy commented Nov 5, 2023

Please see the config from /etc/sudoers file.

@shubhenduanupamdutta
Copy link
Author

I was able to bypass the issue.
I am a novice in Ubuntu. So I have no idea what you want me to do with
"Please see the config from /etc/sudoers file." instruction.
I saw the file. And then???

appleboy added a commit that referenced this issue Nov 5, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
- Add a new job named "testing05" in the ci.yml file
- The job runs on ubuntu-latest
- The job includes steps for checkout and login to GitHub Container Registry
- The login step uses secrets for host, username, key, and port
- The login step includes a script for executing a command

#279
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
appleboy added a commit that referenced this issue Nov 5, 2023
- Remove the line `name: login GitHub Container Registry`
- Add the line `name: sudo command`
- Remove the line `sudo su - -c whoami`
- Add the line `sudo whoami`

#279
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@outinim
Copy link

outinim commented Jan 5, 2024

Up on this matter, I have the same issue when I connect as a service account (aboten) on which all is configured (sudo + ssh - deploy keys) and then try to switch to another account :

======CMD======
echo "Switch user"
whoami
sudo su moutini
whoami
pwd
echo "Activate env"
conda activate ciara_venv

And get this as output:

======END======
out: aboten
err: bash: line 10: conda: command not found
out: aboten
out: /home/aboten
2024/01/05 14:17:22 Process exited with status 127

I stay as the current user aboten instead of switching to user moutini

@outinim
Copy link

outinim commented Jan 5, 2024

Solution founds: launch command as sudo and pipe your instructions on the fly

 sudo su - -c "whoami && echo 'hello world' && touch toto.txt

Returns as planned:

out: root
out: hello world

@appleboy
Copy link
Owner

appleboy commented Jan 7, 2024

@shubhenduanupamdutta Just add the following config to /etc/sudoers file

your_account ALL=(ALL) NOPASSWD:ALL

@appleboy
Copy link
Owner

appleboy commented Jan 7, 2024

Open your /etc/sudoers config and add the following config

deploy ALL=(ALL) NOPASSWD: /usr/bin/whoami

update script

- name: executing ubuntu instance using ssh
  uses: appleboy/ssh-action@v1.0.3
  with:
    host: ${{secrets.HOST_IP}}
    username: ubuntu
    key: ${{secrets.SSH_KEY}}
    port: 22
    request_pty: true
    script:  |
      sudo whoami

see the example:

with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script_stop: true
request_pty: true
command_timeout: 30s
script: |
whoami && echo 'hello world' && touch todo.txt
sudo whoami

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants