Comments (6)
Running interactive shell with sudo -s
is not possible with jumpssh
.
Here you have 2 possibilities:
remote_session.run_cmd("sudo ls -lrt")
Or
remote_session.run_cmd("ls -lrt", username=“root”)
Just few comments on the rest of the code:
- You don’t need to explicitly call
open()
onSSHSession
object, it will be done automatically when running first command - Calling
gateway_session.close()
will automatically close any remote session using this gateway, so no need to close remote_session explicitly
from jumpssh.
@t-cas thanks for the suggestion, But it didn't work for me facing the same issue, I am unable to login to card with root priveledges.
process get in stuck at below line
exit_code, output = remote_session.run_cmd("sudo ssh [email protected]")
even i have tried with
exit_code, output = remote_session.run_cmd("sudo ssh [email protected]**\n**")
After some times its got failed and printed as below
Traceback (most recent call last):
File "D:/PycharmProjects/Python3/ssh/qcserver.py", line 23, in
exit_code, output = remote_session.run_cmd("sudo ssh [email protected]")
File "C:\Users\phitendra\AppData\Local\Programs\Python\Python38\lib\site-packages\jumpssh\session.py", line 387, in run_cmd
raise exception.RunCmdError(exit_code=exit_code,
jumpssh.exception.RunCmdError: Command (sudo ssh [email protected]) returned exit status (-1), expected [0]: STOP!!
[autouser@POC1 ~]$
But I can see that above the last line ([autouser@POC1 ~]$) is exactly what I want to log in and it happens but unfortunately with an error.
from jumpssh.
Update on above, using continuous_output=True
I can see that at the output its logged into successfully into the card which I wanted, But the problem is instead of finishing execution it is getting stuck over there and the program is terminating without executing next line of code.
remote_session.run_cmd("sudo ssh [email protected]", continuous_output=True)
continuous output printed as
[autouser@DTMGR~]$
Can anyone help here what should I do to make it execute successfully?
My code sample is as below
from jumpssh import SSHSession`
gateway_session = SSHSession('10.0.xx.xx', 'autouser', password='pwd123')
remote_session = gateway_session.get_remote_session('10.0.xx.yy', username="autouser", password='pwd123')
print("Exit code is:", remote_session.get_exit_code('ls'))
remote_session.run_cmd("sudo ssh [email protected]", continuous_output=True)
print(remote_session.get_cmd_output('ls'))
print("Closing connection")
gateway_session.close()
from jumpssh.
You cannot ssh interactively with a run_cmd("sudo ssh [email protected]", ...)
Either you get a remote session (if you have permissions):
another_remote_session = remote_session..get_remote_session('10.3.x.xx', username="autouser")
another_remote_session.get_cmd_output('ls')
Or you directly add your command after ssh (this should work in you case, according to last logs provided):
remote_session.get_cmd_output("sudo ssh [email protected] ls")
from jumpssh.
thanks, the second option worked for me remote_session.get_cmd_output("sudo ssh [email protected] ls")
But the problem is to run multiple commands on that card for the operation like find match file and transfer to local i.e its very tuff and challenging as I cannot get another session from a remote session
Thanks @t-cas :)
from jumpssh.
Indeed it will be more challenging for you as you cannot get the extra remote session on 10.3.x.xx
but not impossible ;-)
Glad I could help and good luck to you !
from jumpssh.
Related Issues (20)
- Could not run command in background HOT 1
- Output of Jump-ssh is not getting all receiving inputs from remote client HOT 5
- Ignore error when run command HOT 1
- The close() function does not work as expected. HOT 1
- Troublesome 'package.json' access at runtime in frozen applications HOT 3
- Question: How do I execute: ["sx su -someuser", password, somemorecommands]
- How to execute multiple commands on remote host HOT 2
- Can jumpssh supports parallel ssh connections to different hosts once the jump ssh connection is established ? HOT 1
- Jumpssh from Cisco router to another router causes ChannelException(3, 'Unknown channel type')
- problem using jumpssh dosent upload right remote path, library to ssh a server throught a gateway HOT 2
- "Error reading SSH protocol banner" occured when trying link a remote server through a jump server
- Can't execute background process on remote server HOT 1
- Add optional heartbeat param to run_cmd to check/handle disconnection during long running commands
- cannot upload file to remote server
- Problem when sending multiple commands via jumpSSH using multithreading HOT 2
- Breaks becuase of hardcoding http1.0
- Gateway session can get garbage collected while remote session is still being accessed
- how to connect through two or more getwayhost to the targethost and get the sshclient
- Add ability to select non-interactive shell
- want to ask : cannot jump to router with debug error : DEBUG:paramiko.transport:Rejecting "[email protected]" global request from server.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jumpssh.