Ssh: add proxyjump solution
This commit is contained in:
parent
e8e455ee4d
commit
1e38b26cad
1 changed files with 30 additions and 0 deletions
30
ssh_daemon/proxyjump.py
Normal file
30
ssh_daemon/proxyjump.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
def get_vm_port(username):
|
||||||
|
user_map = {
|
||||||
|
'user0': 9000,
|
||||||
|
'user1': 9001,
|
||||||
|
'user2': 9002
|
||||||
|
}
|
||||||
|
return user_map.get(username)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
username = os.environ.get('USER')
|
||||||
|
if not username:
|
||||||
|
print("Error: Unable to determine username", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
port = 9002 #get_vm_port(username)
|
||||||
|
if not port:
|
||||||
|
print(f"Error: No VM associated with user {username}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Use os.execvp to replace the current process with ssh
|
||||||
|
os.execvp('ssh', ['ssh', '-p', str(port), 'root@localhost'])
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in a new issue