I ssh into several machines that are just IP Addresses, however I noticed a while back that tab completion stopped working when trying to SSH to them. I use zsh and I can tab complete a regular domain name with ssh, but all the IP machines that I use dont tab complete any more, did something break here? or whats the deal?
OS X - 10.9.3
zsh - 5.0.2
have you set the use-ip style?
zstyle ':completion:*' use-ip true
the documentation says that ip addresses are stripped from the host databases by default. use-ip allows completion of them.
http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-use_002dip_002c-completion-style
Your ssh might be hashing the entries at known_hosts?
Best usability solution in general for ssh IMO is to create ssh host aliases, and then just use the alias in the command line. Eg. add something like this to you ~/.ssh/config
Host foo
# HostName also accepts numeric IP addresses
HostName XXX.ZZZ.YYY.BBB
then you just use scp backup.tar foo:
Check man ssh_config for more info. From the manual:
HashKnownHosts
Indicates that ssh(1) should hash host names and addresses when they are added to ~/.ssh/known_hosts. These hashed names
may be used normally by ssh(1) and sshd(8), but they do not reveal identifying information should the file's contents be
disclosed. The default is “no”. Note that existing names and addresses in known hosts files will not be converted auto‐
matically, but may be manually hashed using ssh-keygen(1). Use of this option may break facilities such as tab-comple‐
tion that rely on being able to read unhashed host names from ~/.ssh/known_hosts.
Ok ignore the above, I see in a comment that that is not the case, will leave it there for reference though.
PS: you can always manually set the hosts to be completed by zsh using something along the lines of:
hosts=(foo.bar.com faa.bar.com fee.bar.com)
zstyle ':completion:*:hosts' hosts $hosts
Or do a much more complicated version of it, such as described here https://www.maze.io/2008/08/03/remote-tabcompletion-using-openssh-and-zsh/index.html
Related
Background
Been having a lot if issues with this problem. Randomly PC won't connect to NAS for apparently no reason at all, while others it works. I read tonne of posts about various fixes, some worked sometimes, some didn't, but lately none did. Restarting PC, NAS, or router didn't work, nor did changing settings, checking firewall, antivirus, etc.. Finally I managed to figure it out.
Our nas allow us to make a network name to access it by, like \\MyServer, but sometimes when power goes out, or we have to restart router, this address won't work because the server's local IP had changed, and the address was still cached on our computer to the old one.
The reason can be one of many. In my case, it was none that I could find common answers to.
TL;DR
I randomly can't connect to my NAS via \\MyServer or it's IP \\10.0.0.3, but other PC's can.
I suggest using Synology Assistant. This will find the NAS on the network if it is physically in range.
Then I highly recommend to use a fix IP address for the NAS. It is no good idea having servers with DHCP...
Reason (in my specific case)
Sometimes the PC would only connect to the NAS via IPv6 (almost feel like it does it on a whim), IPv4 won't work at all. That or the old IP is cached on your system.
IPv4 looks something like one of these: 10.0.0.5, 172.16.0.2, or 192.168.0.0
IPv6 looks something like: fe80::842a:a43d:3123:1332
Quick fix attempt first
First, just try opening command prompt and enter ipconfig /flushdns, then try to connect to your usual \\MyServer address, see if that works now.
Didn't work?
What you can try is to see if you can connect via its IPv6 — but first you need to somehow obtain it.
Step 1 In command prompt, type ping MyServer (replaced with whatever name you have), and it see if it manages to ping it. If it does, it will resolve the IP and show an IPv6. If it shows IPv4 or can't connect at all, see further down.
Step 2 Locate the IPv6 at the top, remove % and number after.
Step 3 Replace : with -. Note doubles if you have that: :: with --.
Step 4 Prefix the usual \\ at the start, and add .ipv6-literal.net at the end. Now try to connect to the server using that. With the IPv6 example above, it'd be something like: \\fe80--842a-a43d-3123-1332.ipv6-literal.net
Ping shows IPv4?
Try to ping with one of the other computers, or if you are able to, login to the web dashboard or equivalent on one of those computers, and see if you can find any information about the server's IP's, with goal of finding its IPv6.
Once found, do steps above.
Done!
Other stuff:
IPv6 in browser — remove the % and number, put IP inside brackets [] and then connect. Example: http://[fe80::842a:a43d:3123:1332].
Creating alias of the weird IPv6:
Step 1 Right click Notepad, and open as Administrator
Step 2 Go to File → Open, change the dropdown above 'open' from Textfiles (*.txt) to All files (*.*).
Step 3 Locate the hosts file, located at C:\C:\Windows\System32\drivers\etc\ and open
Step 4 At the bottom, write the IPv6 with the colons AND the %##, then a space, then the alias you want it to use (case insensitive). Example: fe80::842a:a43d:3123:1332%15 MyAlias and save. You should now be able to use \\MyAlias to connect to it.
NOTE The %## number is unique to each computer. E.g. your computer gets %15, the next get %7. The rest of the IP is identical. To get the %## number of a different PC, write ipconfig in its command prompt. It should list its own IPv6 with its appended %## at the end.
Another note: If you need to change an IP in the hosts file of an IP that no longer work, you also need to use ipconfig /flushdns again.
I would like to connect via ssh to certain equipment in a network.
The requisites are:
It must run a command and capture the output of the ssh session in R (or in bash, or any other programming language, but I would prefer it in R language)
It must enter a plain-text password (as this equipment hasn't been accessed before, and can't be changed with a rsa keypair), so the ssh.utils package doesn't meet this requirement
sshpass can't be used, as I have noticed that it doesn't work for some devices I tested.
I've read all this posts but I can't find an effective way to perform it: link 1, link 2, link 3, link 4
I know the requirements are hard to accomplish, but thank you for your effort!
EDIT:
Sorry if I didn't make myself understandable. I mean I work locally in R and I want to connect to +3000 devices in all of my network via ssh. It is Ubiquiti equipment, and the only open ports are 80 and 22.
If ssh doesn't work, I will use the RSelenium package for R and extract info from port 80. But first I will try with ssh pory 22 as it is a lot more efficient than opening an emulated browser.
The big problem in all these Ubiquiti equipment is that they have a password to log in. That's why requisite No.2 is needed. When I must enter a server that I know, I spend time setting up the rsa keypair so that I don't have to enter a password everytime I connect to a specific server, but it's impossible (or at least, for me it's impossible) to configure all +3000 Ubiquiti equipment with these keypairs.
That's why I don't use snmp, for example, as this equipment maybe they have it activated or not, or the snmp configuration is mistaken. I mean, I have to use something that's activated by default, and in a way, ordered. And only port 80 and port 22 are activated and I know all the user's and password's equipment.
And sshpass is an utility in UNIX/Linux like this link explains that works for servers but doesn't work for Ubiquiti equipment, as long as I've tested it. So I can't use it.
The command I need to extract the output from is mca-status. Simply by entering that into the console makes it print some stats I will like to get from the Ubiquiti equipment.
Correct me, please, if I am wrong in something I've posted. Thanks.
I think you have this wrong. I also have no idea what you are trying to say in point 2, and I have not idea what point 3 is supposed to say.
Now: ssh is a authentication mechanism allowing you (trusted) access to another machine and the ability to run a command. This can be as simple as
edd#max:~$ ssh bud Rscript -e '2+2'
[1] 4
edd#max:~$
where I invoke R (or rather, Rscript) on the machine 'bud' (my desktop) from a session on the machine 'max' (my server). That command could be anything including something which writes to temporary or permanent files. You can then retrieve those files via scp.
Authentication is handled independently -- on Unix we often use ssh-agent which run in the background and against you authenticate on login.
Finally I solved it using the rPython package and the python's paramiko module, as there was no way to do it purely via R.
library(rPython)
python.exec(python.code = c("import paramiko",
"ssh = paramiko.SSHClient()",
"ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())",
sprintf('ssh.connect("%s", username="USER", password="PASSWORD") ', IP),
'stdin, stdout, stderr = ssh.exec_command("mca-status")',
'stats = stdout.readlines()'))
I have a large aliases file, and don't want to move it into a DB table. The ask can we have an aliases entry that is delivered to Dovecot and others that are forwarded?
Played with virtual_alias_maps, etc. etc.
Can it be done ?
If MTA expands address to the alias that points to the local address, then LDA occur. If address is expanded to the alias that points to the external domain, then redirection will occur. Both types of aliases have exactly the same semantics and syntax therefore they are traditionally stored in the single file /etc/aliases
I work with another company that is moving from regular FTP to SFTP for their connections. They have informed me that my existing username and password are the same, but that I now need to connect via SFTP on port 22. I have a couple of PHP scripts that do some basic things, like connect to their site, get a directory listing, and upload and download a file each day. Those all work fine on FTP, so I need to just swap out the protocol to SFTP.
After doing some research, the consensus seems to be that phpseclib is the easiest and most robust way to perform SFTP using PHP. My server is running Linux and Apache. I downloaded the library and tried to run just the basic example given by phpseclib, but I get an error:
Notice: SSH_AUTH_SOCK not found in System/SSH/Agent.php on line 244
When I look at Agent.php, I see that the script is looking for SSH_AUTH_SOCK to be defined in either $_SERVER or $_ENV. I must be missing something obvious, but I have no idea how to get past this error.
You are trying to connect to SSH authentication agent (ssh-agent).
When the agent is run, it exports the SSH_AUTH_SOCK environment variable.
What is obviously not happening in your case.
But you didn't tell us, why are you trying to use the agent, if at all. And what did you do to set it up, if anything. So it's difficult to give you a more concrete advice.
See also How is SSH_AUTH_SOCK setup and used by ssh-agent?
Run the bellow command:
eval ssh-agent -s
It works fine for me.
I was looking for list of available options for ftp quote site which will allow to do lot of stuff like executing commands on the target system. Like the below one can be used to submit jobs on mainframes.
quote site filetype=jes
put filetoexecute.jcl
I know that there are similar options for unix environment as well. Is there any list of available options for this quote command for unix, mainframes (windows also if available) environments.
Also below is an extra question based on these.
Is there any way to execute ca7 commands from this ftp? If not I was looking into one rexx example which will execute the ca7 commands passed as arguments. But this is failing with "CA-7 RECEIVER NOT FOUND" error.
PARSE UPPER ARG COMMAND
ADDRESS CA7 COMMAND
SAY 'RC=' RC
X=QUEUED()
SAY 'QUEUED() =' X
DO I=1 TO X
PULL LINE
LINE2=SUBSTR(LINE,2)
SAY LINE2
END
Also the below command is failing with the same failure.
ADDRESS CA7 "'LQ,SEQ=JOB,JOB=*'"
I have checked ca7 manual and don't know how to make sure that CA7 environment is configured to execute the above commands.
Can you please help?
The IBM FTP server supports HELP SITE; this gives you all of the operands that the SITE command supports. You can issue STAT to get the current SITE values.
This is specific to the IBM FTP server. Each FTP server is different, and they may or may not implement the SITE command. I suggest looking at the doc for the FTP server to find if they support SITE and STAT, or similar.