ssh failed to copy local files to the server - ssh

I have connected to the server and I am root user,but my command failed
scp -p 10010 ~/Desktop/usb.sh root#localhost:/
Error:
ssh: connect to host localhost port 22: Connection refused

You'll need a capital P (-P) to specify a port, from the man page:
scp (1):
-P port
Specifies the port to connect to on the remote host. Note that this option is written with a capital 'P', because -p is already reserved for preserving the times and modes of the file in rcp(1).
Also, ensure you user can write to the document root (/), you can always write to your home folder: (root#localhost:/root/)
Fixed command:
scp -P 10010 ~/Desktop/usb.sh root#localhost:/

Related

Can I combine these SSH tunneling commands into one command?

I have a two step solution to access a certain server via SSH:
Step 1, in bash:
ssh -L 127.0.0.1:5000:server2.com:22 server1.com
Step 2, in a new bash session:
ssh -P 5000 127.0.0.1 # This gets me into server2.com
Q1: Is there any way I can combine these two commands into one ssh command, and...
Q2: can I set up one single host entry in my ~/.ssh/config for this connection (allowing me to just type e.g. ssh my-tunnel)?
I suppose this comes down to chaining the hosts in some way. I am new to this and can't quite figure this out...
I came accross this question and was surprised by the fact that ssh supports jump hosts.
You can use single command to connect to the target server while ssh will take care about intermediate hop.
ssh -J server1.com server2.com
-J [user#]host[:port]
Connect to the target host by first making a ssh connection to the jump host and then establishing a TCP
forwarding to the ultimate destination from there. Multiple jump hops may be specified separated by
comma characters. This is a shortcut to specify a ProxyJump configuration directive
And here is the corresponding jump host configuration for SSH config:
Host jumphost
Hostname server1.com
User $YOUR_USERNAME
Port 22
Host my-tunnel
Hostname server2.com
User $YOUR_USERNAME
Port 22
ProxyJump jumphost
...enabling the command: ssh my-tunnel

Why LocalForward in .ssh/config returns error while ssh -L works as expected

I add LocalForward in the .ssh/config file for connecting to the MongoDB on a Ubuntu 14 server.
LocalForward 27017 loccalhost:27017
When I connect to the MongoDB, there is an error message:
channel 9: open failed: administratively prohibited: open failed
However, it works when I use ssh -L in bash
ssh -L 27017:localhost:27017
Is there any difference between these two methods? Can I make it work with the .ssh/config file?

scp + error Name or service not known + custom port

I have read lot of post about this problem but i still can not solve it on my side.
I have a server i used to connect like this:
$ ssh user#xxx.xx.xx.xxx -p yy
user = is not root
xxx.xx.xx.xxx = ipv4 of my server
yy = custom port for ssh
Connexion works well.
I try to make a copy of a folder from my local machine (ubuntu) to the server(ubuntu 14.04) like this:
$ scp -r -p /home/user/my/folder/ ssh://user#xxx.xx.xx.xxx:yy/home/user/my/folder/on/server/
I get this error:
ssh: Could not resolve hostname ssh: Name or service not known
lost connection
I guess the connexion works well. So what could happen? A problem with rights of the folder?
For information, my local machine get both ipv4 and ipv6 address. Could it be that?
Thank you in advance for any help.
jb
Check manual page for scp. It describe the usage of scp with all the switches and options:
scp [...] [-P port] [[user#]host1:]file1 ... [[user#]host2:]file2
Your command should be:
$ scp -r -p -P yy /home/user/my/folder/ user#xxx.xx.xx.xxx:/home/user/my/folder/on/server/
Note port comes as -P yy, you don't write ssh:// in front the user and separate host from the remote path using colon (:).
You don't need "ssh://".
Here scp believes ssh is the name of the server you want to copy to. That's what the message says : "Could not resolve hostname ssh"
Try :
$ scp -r -p -P yy /home/user/my/folder/ user#xxx.xx.xx.xxx/home/user/my/folder/on/server/

openshift ssh access denied

If I try to ssh or git push to openshift, I get the error "access not allowed". The SSH public key is listed on openshift and matches the key in ~/.ssh/id_rsa.pub Linux Mint 17.
dick#dick1 ~ $ ssh-keygen -l
Enter file in which the key is (/home/dick/.ssh/id_rsa):
2048 70:f1:92:9d:d8:7b:09:4c:8e:7d:60:94:53:a0:7a:8a OpenShift-Key (RSA)
dick#dick1 ~ $ rhc sshkey list
default (type: ssh-rsa)
-----------------------
Fingerprint: 70:f1:92:9d:d8:7b:09:4c:8e:7d:60:94:53:a0:7a:8a
Available: true
You have 1 SSH keys associated with your account.
dick#dick1 ~ $ cd /c/src/time
dick#dick1 /c/src/time $ git push
ssh: connect to host time-cronos.rhcloud.com port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
dick#dick1 /c/src/time $ ssh time-cronos.rhcloud.com
ssh: connect to host time-cronos.rhcloud.com port 22: Connection timed out
dick#dick1 /c/src/time $
Sounds like maybe port 22 is blocked where you are? Can you telnet to port 22 at time-cronos.rhcloud.com? If not it might be time to involve your systems administrator or try from another location.
It seems that port 22 is blocked as the connection times out, I would suggest running an nmap scan in order to get more information regarding the port state provided that you have permission to port scan the server:
nmap -p 22 --reason -sT time-cronos.rhcloud.com

How to bypass firewall for RSYNC with SSH tunneling and corkscrew Proxy

I'm trying to use rsync to connect to an Rsync server. However, our company firewall blocks the 873 port used by rsync.
Using the following proxy configuration with corkscrew in the ~/.ssh/config file, I can bypass the firewall and connect to remote servers with SSH:
ProxyCommand /usr/local/bin/corkscrew our-http-proxy.domain.name 8080 %h %p
Thus, with the above configuration, I use ssh the following way, which lets me connect to a remote machine with no problem:
ssh -L 8080:localhost:80 username#remote.machine.name -p 443
My question is, can I use rsync to utilize such ssh tunnel, and connect to the Rsync server?
I so far tried a few ways to have rsync utilize the same ssh proxy configuration. One of them is as follows, which always results in ssh_exchange_identification: Connection closed by remote host:
rsync -CaLvz -e "ssh -L 873:remote.rsync-server.name:443" remote.rsync-server.name::remote-source-directory /local/target/directory/
Any ideas?