Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

specify port for rsync

ubuntu 14.04.4
rsync  version 3.1.0

rsync -rvz -e 'ssh -p 2222' --progress --remove-sent-files ./dir user@host:/path
 
 
rsync --progress -avz -e 'ssh -p 44022' user1@100.126.1.106:/remoteshared /local/dir_A

ssh error

root@server1:~# service ssh restart
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
[....] Restarting OpenBSD Secure Shell server: sshdCould not load host key: /etc/ssh/ssh_host_ecdsa_key

The root cause of this problem is that sshd daemon somehow is not able to load SSH host keys.
When OpenSSH server is first installed on Linux system, SSH host keys should automatically be generated for subsequent use. If, however, key generation was not finished successfully, that can cause SSH login problems like this.
Let's check if SSH host keys are found where they should be.
$ ls -al /etc/ssh/ssh*key 
make sure size is not zero,
good example:-
 root@server1:~# ls -al /etc/ssh/ssh*key
-rw------- 1 root root  668 Nov 30 18:12 /etc/ssh/ssh_host_dsa_key
-rw------- 1 root root  227 Dec  5 15:03 /etc/ssh/ssh_host_ecdsa_key
-rw------- 1 root root 1675 Nov 30 18:12 /etc/ssh/ssh_host_key
-rw------- 1 root root 1671 Nov 30 18:12 /etc/ssh/ssh_host_rsa_key

[SOLUTION - debian / ubuntu ]
root@server1:~# dpkg-reconfigure openssh-server
Creating SSH2 ECDSA key; this may take some time ...
[ ok ] Restarting OpenBSD Secure Shell server: sshd.

[SOLUTION - redhat/centos]
On CentOS, RHEL or Fedora, all you have to do is to restart sshd after removing existing (problematic) keys.
$ sudo rm -r /etc/ssh/ssh*key

$ sudo systemctl restart sshd

An alternative way to regenerate SSH host keys is to manually generate them using ssh-keygen command.
$ sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
$ sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
$ sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key 
Once new SSH host keys are generated, make sure that they are found in /etc/ssh directory. There is no need to restart sshd at this point.
$ ls -al /etc/ssh/ssh*key
Now try to SSH again to the SSH server to see if the problem is gone.

ssh port forward

29 April 2015
Port forwarding (tunneling), especially the local port forwarding, is a very handy feature of SSH. This blog explains local port forwarding in detail first. After that, this blog then introduces remote port forwarding and dynamic port forwarding briefly.

How local port forwarding works

Before getting started, let us assume we have the following three hosts and want to forward all traffics to port 80 of my pc to the port 8080 of target host.
local-port-forwarding-1.png
This is a case which SSH local port forwarding applies. The command to set the tunnel is:
ssh ssh_server -L 80:target:8080
This command set up a SSH connection between my PC and the SSH server. This connection, in addition to working as usual, also acts a tunnel.
local-port-forwarding-2.png
When traffics arrive at port 80 of my pc, they will then go through the tunnel.
local-port-forwarding-3.png

Jump three hops

Note that in fact a traffic can be originated from a forth machine. That is, you can "jump 3 hops" with a single SSH tunnel.
local-port-forwarding-4.png
According to man page, the listening port will, by default, be bond to the loop back interface only. To forward traffics from other machines, one must
  1. Set GatewayPorts in /etc/ssh/sshd_config to "yes".
  2. Specify bind address. For instance (empty or * for any), on ssh client run the following command:
    ssh -L :80:ssh_server:8080 target
    
But according to my test,
  1. GatewayPorts does not take effect.
  2. Remote port forward bind to all interface by default.

Option '-N'

Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).

Remote Port Forwarding

As the name indicates, remote port forwarding is the reverse of local port forwarding. This time, the traffic arrives at the "remote" side will be forwarded to the host on local side.
ssh ssh_server -R :8888:target:8080
ssh ssh_server -R :8888:localhost:8080
remote-port-forwarding.png

Dynamic Port Forwarding

Yet another kind of port forwarding turns your local machine to a socket proxy. For instance, assume that your local machine locates behind firewall and all outgoing HTTP requests are filtered by the firewall. A way to circumvent this restriction is to set up an ssh server outside the firewall and employ the dynamic port forwarding technique.
  1. Run the following command to set up ssh tunnel.
    ssh ssh_server -D 8000
    
  2. Then, in web browser, set proxy as "SOCKS Host" localhost:8000.
Exercise: study the following picture and compare dynamic port forwarding with local port forwarding.
dynamic-port-forwarding.png

enable ssh root login linux

vim /etc/ssh/sshd_config

#PermitRootLogin without-password

PermitRootLogin yes

enable ssh password authentication

vim /etc/ssh/sshd_config
#place below at end of file

PasswordAuthentication yes

##Enable root login

vim /etc/ssh/sshd_config

#PermitRootLogin without-password
PermitRootLogin yes