How to use linux command line ftp with a # sign in my username? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
How can I run this on linux command line when my username has an # sign in the middle?
ftp -u user:password#host/destination_folder/ sourcefile.txt
My username is info#domain.com and it thinks my host is domain.com.
NOTE: This is an unattended upload, so I can't just type in the username and password.

Try this: use "%40" in place of the "#"

As an alternative, if you don't want to create config files, do the unattended upload with curl instead of ftp:
curl -u user:password -T file ftp://server/dir/file

Try to define the account in a ~/.netrc file like this:
machine host login info#domain.com password mypassword
Check man netrc for details.

I simply type ftp hostdomain.com and the very next prompt asked me to enter a name, if it wasn't the same as my current user.
I guess it depends on how your FTP is configured. That is, whether it assumes the same username (if not provided) or asks. the good news is that even without a solution, next time you face this it might Just Work™ for you :D

A more complete answer would be it is not possible with ftp(at least the ftp program installed on centos 6).
Since you wanted an un-attended process, "pts"'s answer will work fine.
Do the unattended upload with curl instead of ftp:
curl -u user:password -T file ftp://server/dir/file
%40 doesn't appear to work.
[~]# ftp domain.com
ftp: connect: Connection refused
ftp> quit
[~]# ftp some_user%40domain.com#domain.com
ftp: some_user%40domain.com#domain.com: Name or service not known
ftp> quit
All I've got is to open the ftp program and use the domain and enter the user when asked. Usually, a password is required anyway, so the interactive nature probably isn't problematic.
[~]# ftp domain.com
Connected to domain.com (173.254.13.235).
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 2 of 1000 allowed.
220-Local time is now 02:47. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Name (domain.com:user): some_user#domain.com
331 User some_user#domain.com OK. Password required
Password:
230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.

curl -f -s --disable-epsv -u someone#somewhere.com:gr8p455w0rd -T /some/dir/filename ftp://somewher.com/ByramHealthcareCenters/byram06-2011.csv

I've never seen the -u parameter. But if you want to use an "#", how about stating it as "\#"?
That way it should be interpreted as you intend. You know something like
ftp -u user\#domain.tld#ftp.host.tld

Related

Bash script check permissions to run command on remote [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have a local development machine and from my bash script am sending commands to the remote server.
How can I write bash code to check if I am allowed to run the remote command so that I can handle the success/failure response from my script?
Alternatively, how can I capture the output so that I can parse it and detect if it succeeded. The difficulty with parsing is that the ssh command might trigger a password prompt so I can't interfere with that.
That bash script uses ssh -qt to send the remote commands
Command
ssh user#host -qt "sudo -u www /usr/local/bin/php /mnt/data/script.php"
Output:
[sudo] password for xxx:
Sorry, user xxx is not allowed to execute '/usr/local/bin/php /mnt/data/script.php' as www on host.domain.com
Assuming that user != root above: you can't - there's no way to read /etc/sudoers or /etc/sudoers.d/* in a normally set-up Linux box if you're not root, so apart from trial & error there's nothing to be done.
As for capturing the result - that's fairly simple (parsing it, of course, is a different story, depending on what you're doing over there).
output=$( ssh user#host -qt "sudo -u www /usr/local/bin/php /mnt/data/script.php" 2>&1 )
After the execution (and you typing the password for sudo)
echo $? # gives you the return-code of what happened on the far end, if it's a success that should be 0
echo $output # gives you the strings to parse

How to auto connect jumper or proxy and server with one command ssh [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I remember one of my friend is using ssh file configuration to make it be done, but I can't find the command that should be written in that file to achieve this result.
So what he did is just type the command
ssh [alias of the server]
and the shell automatically go to jumper (proxy) submit the password in there,
then go to the server and again submit the password there, so he doesn't need to re-enter password during ssh into the server.
Another question, is this able to be done for Windows server?
You can use something like this:
Host jump
User [username]
HostName [ip address]
Host [server ip address] [server alias]
HostName [server ip address]
User [username]
Port [port]
ProxyCommand ssh -q -W %h:%p jump 2>/dev/null
Host Jump is a proxy server.
The command that will help you take a leap on the proxy server then continue to the server is ProxyCommand.
%h: is using your username
%p: is using your password from id_rsa.pub.
Reference: https://www.ssh.com/ssh/config/
I've never tried this except with public key authentication, but assuming:
You want to ssh from origin-box to target-box
target-box has a network name of target.box.domain
origin-box is not authorized on target-box
proxy-box is authorized on target-box
origin-box is authorized on proxy-box
You ssh/config on origin-box would be something like:
Host target-box
ProxyCommand ssh -q proxy-box -W target.box.domain

After aliasing ssh, can't run an explicit ssh command [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I have an alias for ssh'ing to my linux box from my mac machine.
But I am noticing something very weird, or may be I am being stupid.
When I use the alias it works, but when I use what the alias stands for it does not work. For example
bos-mp9ps:~ xyz$ alias ssh
alias ssh='ssh -A xyz#bos-lpaw1'
bos-mp9ps:~ xyz$ ssh -A xyz#bos-lpaw1
bash: xyz#bos-lpaw1: command not found
bos-mp9ps:~ xyz$ ssh
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-65-generic x86_64)
* Documentation: https://help.ubuntu.com/
429 packages can be updated.
0 updates are security updates.
New release '16.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
You have new mail.
Last login: Tue Jan 3 10:29:27 2017 from 172.19.37.47
xyz#bos-lpaw1:~$
Also I am able to ssh into my linux box from private home networks, but not from public networks such as starbucks etc. Do you know if I have to change anything for this ?
My /etc/hosts on linux machine looks like this:
bos-mp9ps:~ xyz$ cat /etc/hosts
# BEGIN hosts added by Pulse
23.79.238.45 vpn.company.com
# END hosts added by Pulse
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
When I use my linux's box's IP address to login it does not help and it brings me to same position
bos-mp9ps:~ xyz$ command ssh xyz#172.19.37.47
The authenticity of host '172.19.37.47 (172.19.37.47)' can't be established.
ECDSA key fingerprint is SHA256:MQwHj9JTw5d2Vzbz5h5hw2KxmhKmREVGIcrY+PrBxQc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.19.37.47' (ECDSA) to the list of known hosts.
Password:
Last login: Thu Dec 29 15:18:10 2016
Agent pid 971
bos-mp9ps:~ xyz$
Thank you for reading
The others have answered how do fix your alias, but I think the best way of doing this is actually to dispense with aliases altogether and use the ssh configuration file, which is usually in ~/.ssh/config. To match what your alias does, you would put something like this in it (assuming it's using OpenSSH or something similar):
Host linux
User xyz
HostName bos-lpaw1
ForwardAgent yes
With this in place, you would log in to the computer like this:
$ ssh linux
(you can give it any host alias you want, it doesn't have to be "linux").
Why should you do it this way? There are several advantages:
Since you're not hardcoding which host you're logging into like your original alias did, you are free to log into multiple different computers (but you can get this by making one alias for each target computer, so the alias method can also support this).
Host aliases described in .ssh/config are also recognized by rsync and scp. So you are automatically able to do stuff like rsync a.txt linux:b.txt to copy a.txt to the linux computer and naming it b.txt.
To be able to ssh into your computer from public networks, you need a way to get the IP address of your computer. You can either try to set this up using DNS (though that can be a hassle) or if your IP doesn't change very often you can just hard-code it. Of course, if you use Network Adress Translation you will probably need to set up port forwarding on your modem/router, so that incoming connections to your global address get forwarded to the correct local computer.
Problem
ssh is aliased to 'ssh -A xyz#bos-lpaw1'
so
ssh -A xyz#bos-lpaw1
is converted to
ssh -A xyz#bos-lpaw1 -A xyz#bos-lpaw1
So this command is trying to execute the "command" xyz#bos-lpaw1 by the user xyz on the server bos-lpaw1.
Solution
Another alias
Replace
alias ssh='ssh -A xyz#bos-lpaw1'
with
alias sshlpaw='ssh -A xyz#bos-lpaw1'
ssh is a very important program, overriding it with an alias isn't a good idea.
Prevent alias with command
For the cases where you need the usual ssh without alias, you can type :
command ssh -A xyz#bos-lpaw1
in your terminal.
use .ssh/config
see #amaurea's excellent answer.

How to copy files over ssh [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
How do I copy a file using ssh from my test server to my production server, how do I do this for a single file and how do I do this for multiple files?
From Window to Linux
Download https://cygwin.com/ this will give you a proper terminal which will then allow you to run the linux commands as listed below in the From Linux to Linux section.
From Linux to Linux
The essential command is this
The command
scp [ssh login to remote server]:[filepath] [local filepath]
To copy a single file example
scp user#your.server.example.com:/path/to/foo/[filename] /home/user/Desktop/[filename]
To copy a directory example
scp -r user#your.server.example.com:/path/to/foo /home/user/Desktop/
To use full power of scp you need to go through next steps:
Setup public key authentication
Create ssh aliases
Then, for example if you'll have this ~/.ssh/config:
Host test
User testuser
HostName test-site.com
Port 22022
Host prod
User produser
HostName production-site.com
Port 22022
you'll save yourself from password entry and simplify scp syntax like this:
scp -r prod:/path/foo /home/user/Desktop # copy to local
scp -r prod:/path/foo test:/tmp # copy from remote prod to remote test
More over, you will be able to use remote path-completion:
scp test:/var/log/ # press tab twice
Display all 151 possibilities? (y or n)

how to make ssh fail if any parameter is wrong [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm using the command ssh -i /home/ssh_keys/10_1_1_127 root#10.1.1.127 date for checking the date on some other machine,
If some parameter is wrong, like the user, the ip or the identity file doesn't exists,
ssh asks for password
for example, if I write ssh -i /home/ssh_keys/10_1_1_1277 root#10.1.1.127 date
whilst /home/ssh_keys/10_1_1_1277 doesn't exists, I get:
root#10.1.1.127's password:
I wanted to know if it is possible, and if so, then how to make ssh fail if some parameter isn't right, so ssh won't ask me for a password if I enter wrong parameters...
Thanks
All these changes should be done via root or a sudo enabled user.
In /etc/ssh/sshd_config set the following entries to no:
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no
If you need help finding those specific lines, use grep:
grep -n "PasswordAuthentication" /etc/ssh/sshd_config
^^or whatever^^
This outputs the line number
Then restart ssh
/etc/init.d/ssh restart
or
service ssh restart
depending on your flavor of Linux.

Resources