File size: 1,433 Bytes
5e0532d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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()