Giter Site home page Giter Site logo

Comments (2)

mimicarina avatar mimicarina commented on June 12, 2024

I experimented with this and the below worked for me. Need to run the ssh-add as sudo and keep environment variables set with -e.

#!/bin/bash
set -e

sudo -u ec2-user -i <<'EOF'
unset SUDO_UID
echo "Activate agent"
cd /home/ec2-user
eval `ssh-agent -s`
ssh-add /home/ec2-user/SageMaker/.ssh/id_rsa
echo "Check for key"
ps aux | grep ssh

EOF

from amazon-sagemaker-notebook-instance-lifecycle-config-samples.

markjreed avatar markjreed commented on June 12, 2024

? "set -e" doesn't "keep environment variables set". It turns on the "errexit" (error exit) flag, which will cause the whole script to terminate immediately if any of the commands it runs signals an error.

I don't know why you are unsetting SUDO_UID; ssh-agent doesn't have any references to that. And SUDO_USER will still be set to the original username.

Note that ssh-agent is for keeping keys around in memory so (1) you can forward the agent connection for use on machines that don't have the key on their file systems, and (2) you don't have to type a passphrase every time you run an ssh command. If the key is already in a file on the instance and not passphrase protected, you don't need ssh-agent; just tell ssh to use that file (e.g. by putting IdentityFile /home/ec2-user/SageMaker/.ssh/id_rsa in /home/ec2-user/.ssh/config).

from amazon-sagemaker-notebook-instance-lifecycle-config-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.