netmiko error after connection established: Router prompt not found - netmiko

Using python3.7 and netmiko 3.4.0.
I'm trying to connect to a Linux Ubuntu 18 server. I see that Netmiko can ssh login, but afterwards it fails with the error shown below. This is using 'device_type=linux'. If I use 'device_type=generic' I don't see the error, however this device type is not supported by the file_transfer, which requires 'linux'.
In summary, when the connection is established using device type 'linux' , netmiko throws the following error:
user_id#my-host-name ~ >
DEBUG:netmiko:Clear buffer detects data in the channel
DEBUG:netmiko:read_channel:
DEBUG:netmiko:[find_prompt()]: prompt is user_id#my-host-name ~ >
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
user_id#my-host-name ~ >
DEBUG:netmiko:read_channel:
DEBUG:netmiko:[find_prompt()]: prompt is user_id#my-host-name ~ >
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:Pattern is:
user_id#my-host-name ~ >
user_id#my-host-name ~ >
DEBUG:netmiko:write_channel: b'exit\n'
DEBUG:paramiko.transport:EOF in transport thread
ERROR:root:Error when attempting to connect with SSH: Router prompt not found: 'user_id#my-host-name ~ >'
Why does Netmiko it fail , since it had established the SSH connection successfully? Is there a work around to avoid this failure?

After some further debugging, I think I found the root cause.
My linux prompt ends with ">"
In linux_ssh, the default prompts are defined as follows:
LINUX_PROMPT_PRI = os.getenv("NETMIKO_LINUX_PROMPT_PRI", "$")
LINUX_PROMPT_ALT = os.getenv("NETMIKO_LINUX_PROMPT_ALT", "#")
LINUX_PROMPT_ROOT = os.getenv("NETMIKO_LINUX_PROMPT_ROOT", "#")
Therefore, Netmiko doesn't seem to match my prompt, and therefore it fails as shown above.
The workaround I found is disabling auto connect, and changing the linux prompt
ConnectHandler(**parameters)
establish_connection()
set_base_prompt(alt_prompt_terminator='>')
Parameters contains 'auto_connect': False

Netmiko works by screen scraping. Meaning it knows it has finished executing the command if the prompt is returned. If you change the prompt, Netmiko will not know if your command finished, and will probably timeout.
DEBUG:netmiko:write_channel: b'exit\n'
Probably changes the prompt. If you use send_command you can add the expect_string parameter:
https://ktbyers.github.io/netmiko/docs/netmiko/index.html#netmiko.BaseConnection.send_command

Related

Raspberry Pi errors on VNC login and ssh startup

For some weird reason, this two errors started occurring on ssh connection initiation:
-bash: id: command not found
-bash: [: : integer expression expected
I'm not sure how those errors affect me, but in the last few days my VNC connection to raspberry pi also stopped working (I can see the login screen in the VNC viewer, but after i put my credentials, the screen turns black for a moment and then returns to the same login screen which I'm stuck on...)
I've tried updating my pi version through ssh and use some other commands I've found online, but nothing worked. Any idea how to solve those problems?
It looks like something is trying to load on login.
The places to check are as follows:
~/.bashrc
~/.bash_profile
~/.profile
~/.profile gets ran each time you login to the shell and the others run when running the bash shell.
By the looks of it something is trying to run the command id and as its not installed it's not running.
A quick test to see if this is in any of your files would to run grep in your home area.
# Change to your home area
cd ~/
# Recursively search for a string matching "id"
grep -rsi "id" .
This could explain why VNC is not working, as when you try to login to VNC it tries to load your config from those files and if they error VNC might not launch.

mosh + osx + /bin/false error

I have successfully installed mosh at server and client side both. I am trying to ssh using mosh from osx but it is throwing following error:
/bin/false: No such file or directory
write: Broken pipe
/usr/local/bin/mosh: Did not find remote IP address (is SSH ProxyCommand disabled?).
I am not sure if it has anything to do with mosh, or it is general error. Please help me in setting up mosh.
This error
/bin/false: No such file or directory
most likely means the user account that you are trying to login to is disabled. You need to log in as another user, and change the shell to a valid executable
$ chsh -s /bin/bash [username]

shrewsoft command line interface to connect and terminate vpn on ubuntu

Shrewsoft [1] provides a command line interface for setting up the vpn tunnel automatically without any user intervention, such as by using the following command
ikec -u username -p password -r configuration -a
IS there any way to detect if the connect attempt was successful such as by reading live logs and how can we terminate the vpn tunnel after some time using the command line. Any help will be appreciable.
By looking at the terminal output from ikec -u username -p password -r configuration -a, you can tell if the connection was successful; if the output has a line ii : tunnel enabled, that means the connection was successful and should work. If you get a message such as >> : detached from key daemon or failed to connect to key daemon, it means there was a problem with the connection (https://askubuntu.com/a/793336/705434 suggests running sudo /usr/sbin/iked for a solution to this particular error). To exit the ikec command, just type q into the terminal.
EDIT: it looks like this page (https://gist.github.com/fschabmeyer/22b759994cf852df7e9b) has a shell script that can handle the detection, you should be able to add a case to exit the command automatically after a certain amount of time.

X11 connection rejected because of wrong authentication

I am getting a error while accessing the firefox using X11Forwarding.
[root#station2 ~]# firefox
KiTTY X11 proxy: wrong authorisation protocol attemptedKiTTY X11 proxy: wrong authorisation protocol attemptedError: cannot open display: localhost:10.0
setup the following values: /etc/ssh/sshd_config
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
** Installed the package**
#yum install xorg-x11-xauth
#yum -y install xauth
[root#station2 .ssh]# echo $DISPLAY
localhost:10.0
#mkxauth -c
adding key for station2.example.com to /root/.Xauthority ... done
export XAUTHORITY=$HOME/.Xauthority
This fix worked for me
There is a hard, if not even impossible, to find (by search engine) scenario that may may cause that error message.
Preliminary note: The topic of this answer is not to discuss if it is a safety
risc or recommondable at all to use a graphical desktop as root on an remote, display-less, webserver.
Scenario:
A remote internet connected Linux server S has assigned the domain
name example.com to it's public IP4-address 192.0.2.1.
The /etc/hostname file on S contains the single line example.
The /etc/hosts
file on S contains the line 127.0.0.1 localhost example.com example.
The (remote) ssh access to S is by (sshd-) configuration (on S) forbidden
for root by the line DenyUsers root in /etc/ssh/sshd_config, but
allowed for a dummy user user1. From a client computer C a ssh
connection, using the ssh parameter -X or -Y, is established to S
as user user1.
Then, in a remote terminal on S owned by user1,
if any X11 related command is tried to be executed as root, may it be by
su, then trying to start the X11 desktop environment
or, as in the concrete case executing a script containing
#!/bin/bash
su --preserve-environment -c "xfce4-session &" root
the error message
X11 connection rejected because of wrong authentication.
is output and the start of any X11 related program fails.
The DISPLAY variable of root's environment contains
example.com:10.0
then.
One solution to the problem is, in this special case, to modify the line
127.0.0.1 localhost example.com example
in /etc/hosts to
127.0.0.1 localhost
Solution: run the application with the same user you are SSHing.
I have also encounter such errors while using X11.
The source of my problem was that i used SSH with my own username (which was not root).
Then, once logged in i tired running stuff with X11 while doing "su" or doing "sudo",
the problem with that is that the SSH session is configured with your own username - e.g: Raj, but then you switch to user root which is not part of the X11 session.
So what you should do is simply try to run the application (firefox in your case) with the same user you started the X11 session.
Hope this helps.
Talel.
I ran into this running gvim over ssh -t -Y and the solution that worked for me was:
xauth add $(xauth -f ~<logon_user>/.Xauthority list | tail -1) ; export NO_AT_BRIDGE=1 # gvim X11 fix for remote GUI failure after su
I do not know where I stumbled on this answer so I cannot give credit to the author.

Windows TortoiseHg plink hangs AFTER clone/push

We have an all Windows network and I'm trying to get Tortoise Mercurial up and running over SSH for a central repo for our small team to use. I can get it working for the most part but plink/tortoiseplink hang AFTER executing commands successfully (clone/push etc.)
I've set up Freesshd on our Widnows 2008 rc2 server along with Tortoise Hg. I've generated myself a public/private key on the server (was having issues generating on the client) using PuttyGen. Private key I copied to my client and updated mercurial.ini. Public key I renamed and updated Freesshd to point at the folder containing the public keys.
On the client side I have registered my private key with Pageant, created a session in Putty along with pointing it at my private key and saved it.
When I use Putty to make my initial connection, things start to go odd.
I get a command prompt for user name (no prompt for password) and, at the command prompt (after authentication), I can't type.
Perhaps an issue with Putty. I'll try using Tortoise via (TortoisePlink.exe).
In mercurial.ini I have:
[ui]
ssh = "C:\putty\TortoisePlink.exe" -ssh -2 -batch -C -i C:\Users\Jude.ssh\JudePrivate.ppk
If I use the console I can clone the repo but it hangs AFTER doing everything. Using --debug, the last line is:
3 files updated, O files merged, 0 files removed, 0 files unresolved
Kind of what I would expect as the files do get clones. But then I can't do anything else. Ctrl+C does nothing and I have to kill the process. (Which by the way, then shows the Ctrl^C at the command prompt as well as the rest of the keyboard mashing).
The repo gets cloned, the correct version of the files appear but the console window doesn't close or give me back control.
If I try using the Hg Workbench, I get a similar issue. I can clone and push - it actually happens - but using the GUI I get:
% hg --repository C:\repositories\HgTest push --debug
ssh://Jude#dev01:22/d:/repositories/hgtest
pushing to ssh://Jude#dev01:22/d:/repositories/hgtest
running "C:\putty\TortoisePlink.exe" -ssh -2 -batch -C -i
C:\Users\Jude\.ssh\JudePrivate.ppk Jude#dev01 -P 22 "hg -R d:/repositories/hgtest serve --stdio"
sending hello command
sending between command
remote: 145
remote: capabilities: lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch stream unbundle=HG10GZ,HG10BZ,HG10UN httpheader=1024
remote: 1
query 1; heads
sending batch command
searching for changes
all local heads known remotely
no changes found
sending listkeys command
checking for updated bookmarks
sending listkeys command
The green bar at the top of the Workbench says "Pushing to ssh://Jude#dev01:22/d:/repositories/hgtest..." as does the status bar at the bottom. I left it like this all weekend and when I came back it was still like it. I can still use the Hg Workbench (kind of) but can't use pull/push/clone. Trying to close the Hg Workbench results in the message (in status bar) Sync tab cannot exit and I can't close the app. Killing TortoisePlink.exe (or Plink.exe, whichever I try) frees up the app I can use it or close it as normal.
Initially I thought it was a problem with TortoiseHg or TortoisePlink but downloading Plink from the Putty site results in the same.
To clarify:
- I can push/clone via SSH and no password prompt
- I can do this via the command line or the Hg Workbench
- Irrespective of which method I use (or Plink.exe or TortoisePlink.exe) the process needs to be manually killed.
Software used + versions
Client (Windows Vista 32bit)
Tortoise Hg 2.3 (merc 2.1, Python 2.6.6)
Plink 0.62
Server - (Windows 2008 server rc2)
FreeSSHd 1.2.4
Same Tortoise as above
Lots of searching has yielded nothing of use. I've tried all suggestions I've seen (even if marginally related) but to no avail. As the actual functions are working I assume I've set up correctly the keys, SSH, Tortoise etc.
I'm hoping I'm missing a simple option somewhere but I suspect that it's awaiting some kind of user prompt.
Fingers crossed :)
=== UPDATE ===
I've found the event log for Putty (right click putty console window, voila, "Event Log" option. Once I've loaded the session and clicked open, I get the console window and a login as: prompt. After typing my name and hitting return, I get:
Reading private key file "C:\Users\Jude\.ssh\JudePrivate.ppk"
Pageant is running. Requesting keys.
Failed to get reply from Pageant
Offered public key
Offer of public key accepted
Sent public key signature
Access granted
Opened channel for session
Allocated pty (ospeed 38400bps, ispeed 38400bps)
Started a shell/command
And it's at this stage I the command prompt changes to c:\Windows\system32> and can't type anything.
=== UPDATE 2 ===
Using plink I do the following at the console:
plink -v -ssh Jude#dev01 "cmd /c echo hello"
and, as well as all the info -v gives, I see hello then Server sent command exist status 0 and Disconnected: All channels closed. This is what I would expect.
If I do it with tortoiseplink, `tortoiseplink-v -ssh Jude#dev01 "cmd /c echo hello"' I see nothing returned or written to the window and I get a command prompt again.
This implies SSH is working as is the alias (dev01). But should I see something when using TortoisePlink?
Typing hg clone --verbose -- ssh://Jude#dev01/d:/repositories/hgtest C:\repositories\test again fetches the files, copies them to the test folder but then doesn't return the command prompt. Last line is 3 files updated... etc.
=== UPDATE 3 ===
It seems hg.exe is spawned by FreeSSHd on the server and it does close/finish. When the hg.exe process is killed on the server, the client (console/clone dialogue box) behaves and finished the command gracefully.
To clarify:
I use clone from command line or HG Workbench and specify repo alias
According to the logs everything is fine, I'm authenticated, the files are pulled down via SSH and copied to the local repo I specified in 1
At this point it hangs - whether the console or HG Workbench or right click/clone option.
Using Process Explorer on the server allows me to kill hg.exe spawned by the FreeSSHd service
As soon as I do this the client says "command completed successfully".
So, it now seems to be an issue with Tortoise Hg on the server. Maybe FreeSSHd and Tortoise don't play well together... I suppose I'll reinstall everything...
=== UPDATE 4 ===
It seems I'm not the only one with this issue. I had spotted this before on SO but it wasn't relevant at the time. However, now I'm getting the same problem: Mercurial over ssh client and server on Windows
That problem wasn't solved (two years ago) so shall I keep this question open?
First of all - read docs!
hg help urls
Valid URLs are of the form:
....
ssh://[user#]host[:port]/[path][#revision]
Plink uses -l option for username
Debug successful ssh-connect (and usable path) with pure TortoisePlink, remove all unnecessary options

Resources