mirror of https://github.com/jumpserver/jumpserver
modify PS1
parent
e0a0c1c641
commit
f06422d5fa
11
connect.py
11
connect.py
|
@ -106,7 +106,7 @@ def connect(username, password, host, port):
|
||||||
Connect server.
|
Connect server.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ps1 = '[\u@%s \W]\$' % host
|
ps1 = "'[\u@%s \W]\$ '\n" % host
|
||||||
|
|
||||||
# Make a ssh connection
|
# Make a ssh connection
|
||||||
ssh = paramiko.SSHClient()
|
ssh = paramiko.SSHClient()
|
||||||
|
@ -114,9 +114,11 @@ def connect(username, password, host, port):
|
||||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
ssh.connect(host, port=port, username=username, password=password, compress=True)
|
ssh.connect(host, port=port, username=username, password=password, compress=True)
|
||||||
|
|
||||||
# Make a channel
|
# Make a channel and set windows size
|
||||||
global channel
|
global channel
|
||||||
channel = ssh.invoke_shell()
|
channel = ssh.invoke_shell()
|
||||||
|
win_size = get_win_size()
|
||||||
|
channel.resize_pty(height=win_size[0], width=win_size[1])
|
||||||
try:
|
try:
|
||||||
signal.signal(signal.SIGWINCH, set_win_size)
|
signal.signal(signal.SIGWINCH, set_win_size)
|
||||||
except:
|
except:
|
||||||
|
@ -124,16 +126,15 @@ def connect(username, password, host, port):
|
||||||
|
|
||||||
# Modify PS1
|
# Modify PS1
|
||||||
channel.send('PS1=%s' % ps1)
|
channel.send('PS1=%s' % ps1)
|
||||||
|
channel.send("clear;echo -e '\\033[32mLogin %s OK.\\033[0m'\n" % host)
|
||||||
|
|
||||||
# Make ssh interactive tunnel
|
# Make ssh interactive tunnel
|
||||||
posix_shell(channel, username, host)
|
posix_shell(channel, username, host)
|
||||||
|
|
||||||
# shutdown channel socket
|
# shutdown channel socket
|
||||||
channel.shutdown()
|
ssh.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
connect('guanghongwei', 'Lov@j1ax1n', '172.16.1.122', 2001)
|
connect('guanghongwei', 'Lov@j1ax1n', '172.16.1.122', 2001)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue