I need to connect to an sftp server from Mac OS X and the username given is an email address (someone#example.com)
So my connection string looks like:
sftp someone#example.com#ftp.example.com
The connection does not accept the password so I assume it is confused by the double "#".
I tried to escape the first "#" with "\#" But that crashed the sftp server and would only have an effect for the shell I'd think.
What is the proper way to escape this in order to get it to work.
Unfortunately the sftp command on Mac OS X does not allow me an option for interactive username prompt.
Add an entry for the host in ~/.ssh/config that has the desired name.
Host stupidadminhost
HostName ssh.example.com
User somewhere#outthere.com
Then just SFTP to stupidadminhost instead, with no given username.
sftp -o User=someone#example.com ftp.example.com
As a workaround I use YummyFTP. It bypasses a lot of the complicated options and gives you a visual interface. It has been a time saver for me with lots of different sites to interact with.
sftp "someone#example.com"#ftp.example.com
This does the trick too.
Related
I have a headless file server on which I store and manage downloads and media, but occasionally I have to transfer small files back to my computer (Mac, using bash shell). The problem is that some files have more user-friendly names and commonly have spaces in them, and they are buried in the file directory hierarchy I have set up on my server.
When I'm using scp from my local machine, I don't have tab completion, so I have to manually type out the entire path and name with spaces escaped. When I ssh into the server first, the command:
scp /home/me/files/file\ name\ with\ spaces.png Me#localhost:/Users/Me/MyDirectory
fails with the error "Permission denied, please try again" even though I'm entering my local machine user password properly.
I've learned a little bit of sftp since I've been told that may be a better tool for file transfer. However, the utility seems outdated and I still don't have tab completion after establishing a connection to the server (on my Terminal when pressing Tab I just get a tab character).
My question is this: what can I do to allow tab completion while using scp from my Mac? Or am I using incorrect syntax for scp while in an ssh session, and is there something in that command I should fix? Or, is there a (better? newer?) tool other than sftp that would offer tab completion on a server?
Finally, if none of these problems have simple solutions, is there some package I could install (e.g. a completion package from Homebrew or the like) that would facilitate better tab-completion with any of these commands?
Looks to me like this is some incorrect scping.
This is the format of the command
scp ./localFile.txt remoteUser#remoteHost:/remoteFile.txt
You were so close, but you have localhost set where you should have your remoteHost.
localhost is the name that resolves to the machine that you are currently on - so in your workflow, you are sshing to a machine, and then trying to scp that file to the same machine you are already sshd into.
What you need to do, is figure out the IP address, or the physical host name of the computer that you are trying to connect to, and use that instead.
scp ./localFile.txt remoteUser#192.168.1.100:/remoteFile.txt
# where 192.168.1.100 would be the IP of your Mac
I am assuming the reason you were getting permission denied, was because you were using your the login credentials for you mac, but unknowingly trying to login again to your headless machine.
I am trying to remotely add a user to a MikroTik router via terminal. Firstly I am opening PuTTY and then I type the right command to add the user but I always take the same mistake:
"Unable to open connection to 1.1.1.1.1" (here is my real address)
"Network Error: Cannot assign requested address"
What should I do?
The command that I insert to cmd is:
putty -ssh username#1.1.1.1.1 22 -pw mypass '/ip hotspot user add limit-uptime=1h server=all name=user1 password=user1'
Thank you in advance
The error message is really confusing. PuTTY got obviously confused by your wrong command-line syntax:
You have to specify the port number using the -P switch. Though you do not need to specify the port number at all, if it is the standard 22.
You cannot specify the command on the command-line of PuTTY. You need to use the PLink for that.
Do not quote the command, unless the quotes are really part of the command.
IP address has 4 numeric components, not 5. But I assume it is just a typo, when you obfuscated your real IP address.
plink.exe -ssh username#1.2.3.4 -P 22 -pw mypass /ip hotspot user add limit-uptime=1h server=all name=user1 password=user1
References:
The PuTTY command line
Using the command-line connection tool Plink
I'm figuring out how to best create a bash script that accepts username, password and host as input and can then use ssh/rsync/scp to connect. It seems that these programs only accept password that is given by the user via prompt.
Note: I am well familiar with SSH keys - my use case is a situation where one wants to programmatically place an SSH key to a server where a key does not exist.
My current solution is to use expect to answer the password prompt with the correct password (and provide all other information as parameters).
See https://gist.github.com/elnygren/965a6db4f3fd8e242e90
If you do not mind your password being visible to other users you could use sshpass as suggested in this answer:
sshpass -p<password> ssh <arguments>
The best solution for jobs like these (connecting anything over SSH, be it ssh itself, scp or rsync) is to use keys for authentification.
Then you can add your key to the auth manager (or just leave it without passphrase, but then be careful!) and use it to connect to the host.
I have to write a shell script which ssh to another server with other username without actually asking for a password from the user?
Due to constraints I cannot use key based authentication.
let,
Source Server -- abc.efg.com
Source UserName -- tom
Source Password -- tom123
Destination Server -- xyz.efc.com
Destination UserName -- bob
destination Password -- bob123
I have to place the bash script in source server.
Please let me know if something could be done using expect tool and/or sshpass.
It is okay for me to hardcode the password for destination server in the bash script but I cannot bear an interactive session, simply when I run he script, I want to see the destination server logged in with another username.
Thanks in Advance.
You want to use key-authentication http://ornellas.apanela.com/dokuwiki/pub:ssh_key_auth
Generate your keys ssh-keygen
Copy the keys to your new box ssh-copy-id -i ~/.ssh/id_rsa.pub me#otherhost.com
ssh to other host without password ssh me#otherhost.com
You can use expect to wrap ssh, but it's pretty hectic, and fails easily when there are network errors, so test it well or use a script specifically designed for wrapping ssh passwords. Key based authentication is better.
You can prevent interactive sessions by redirecting standard input from the null device, ie.
ssh me#destination destination-command < /dev/null
About placing the script in the source server, if the script you are running is local, rather than remote, then you can pass the script on standard input, rather than the command line:
cat bashscript.sh | ssh me#destination
You can install the sshpass program, which lets you write a script like
#!/bin/bash
sshpass -p bob123 ssh UserName#xyz.efc.com
The answer is that you can't as OpenSSH actively prevent headless password-based authentication. Use key-based authentication.
You may be able to fork the OpenSSH client code and patch it, but I think that is a bit excessive.
I want to write one shell script like
command1
ssh vivek#remotehost
fire command on remote host
Now I have password in pass.txt . But when I change stdin with file. It is not reading password from file.
script.sh < password.txt
It is prompting for the password in place of reading password from the file.
What I am doing wrong ?
Second problem is that shell script don't shows the command fired. Is there a way , I can show fired command from it ?
Note :
I don't have key based access on remote system. I can only use password based login for ssh.
You can use ssh-agent or expect (the programing language) to do this.
OpenSSH ssh does not reads the password from stdin but from /dev/tty. That's why you have to use Expect or some other similar tool to automate it.
plink is another client, also available for Linux/Unix that accepts the password as a parameter on the command line... though that has some ugly security implications.
Okay, just to mention yet another option: sshpass is a tool developed for exactly the task of "fooling" regular openssh client to accept password non-interactively.