Spaces:
Sleeping
Sleeping
| import os | |
| def update_ssh_config(): | |
| ssh_dir = os.path.expanduser("~/.ssh") | |
| config_path = os.path.join(ssh_dir, "config") | |
| # Cloudflared path (hardcoded to workspace based on previous context) | |
| cloudflared_path = r"C:\Users\max\ORA\cloudflared.exe" | |
| block = f""" | |
| Host google_colab_ssh | |
| HostName clients-refused-besides-seat.trycloudflare.com | |
| User root | |
| Port 22 | |
| ProxyCommand {cloudflared_path} access ssh --hostname %h | |
| """ | |
| if not os.path.exists(ssh_dir): | |
| print(f"Creating directory: {ssh_dir}") | |
| os.makedirs(ssh_dir) | |
| print(f"Updating {config_path}...") | |
| current_content = "" | |
| if os.path.exists(config_path): | |
| with open(config_path, "r") as f: | |
| current_content = f.read() | |
| if "Host google_colab_ssh" in current_content: | |
| print("Config already contains 'Host google_colab_ssh'. Skipping append to avoid duplicates.") | |
| # Optional strategy: Replace it? For now, assume manual intervention if it exists but is wrong. | |
| # Check if the hostname matches? | |
| if "clients-refused-besides-seat.trycloudflare.com" not in current_content: | |
| print("WARNING: Existing config has different HostName. Please check manually.") | |
| else: | |
| with open(config_path, "a") as f: | |
| f.write("\n" + block) | |
| print("Successfully appended configuration.") | |
| if __name__ == "__main__": | |
| update_ssh_config() | |