Skip to content

Commit

Permalink
add AddKeysToAgent for ssh config file and ssh cmd (#3985)
Browse files Browse the repository at this point in the history
* add AddKeysToAgent for ssh config file and ssh cmd

* fix pylint line too long

* renmae to mpirun.yaml

* update comment

* reformat

* hint if ssh-agent not running

* reformat

* pylint

* pytest

* revert ssh agent checking

---------

Co-authored-by: root <root@cheery-slab-8.localdomain>
  • Loading branch information
zpoint and root authored Sep 27, 2024
1 parent 5cef688 commit e6b8d2c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/mpirun.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
workdir: .

resources:
cloud: aws

num_nodes: 2 # Total number of nodes (1 head + 1 worker)

setup: |
echo "Running setup on node ${SKYPILOT_NODE_RANK}."
# Install MPI if not already present. This will vary based on your OS/distro.
sudo apt update
sudo apt install -y openmpi-bin openmpi-common libopenmpi-dev
run: |
if [ "${SKYPILOT_NODE_RANK}" == "0" ]; then
echo "head node"
num_nodes=`echo "$SKYPILOT_NODE_IPS" | wc -l`
mpi_nodes=$(echo "$SKYPILOT_NODE_IPS" | tr '\n' ',')
mpi_nodes=${mpi_nodes::-1}
echo "$mpi_nodes"
mpirun -np $num_nodes -H $mpi_nodes bash -c 'echo "mpirun hello from IP $(hostname -I)"'
else
echo "worker nodes"
fi
1 change: 1 addition & 0 deletions sky/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def _get_generated_config(cls, autogen_comment: str, host_name: str,
HostName {ip}
User {username}
IdentityFile {ssh_key_path}
AddKeysToAgent yes
IdentitiesOnly yes
ForwardAgent yes
StrictHostKeyChecking no
Expand Down
2 changes: 2 additions & 0 deletions sky/provision/provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def _ssh_probe_command(ip: str,
'-o',
'IdentitiesOnly=yes',
'-o',
'AddKeysToAgent=yes',
'-o',
'ExitOnForwardFailure=yes',
'-o',
'ServerAliveInterval=5',
Expand Down
4 changes: 4 additions & 0 deletions sky/utils/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def ssh_options_list(
'LogLevel': 'ERROR',
# Try fewer extraneous key pairs.
'IdentitiesOnly': 'yes',
# Add the current private key used for this SSH connection to the
# SSH agent, so that forward agent parameter will then make SSH
# agent forward it.
'AddKeysToAgent': 'yes',
# Abort if port forwarding fails (instead of just printing to
# stderr).
'ExitOnForwardFailure': 'yes',
Expand Down

0 comments on commit e6b8d2c

Please sign in to comment.