關於ssh: connect to host IP port 22: Connection refused

關於ssh: connect to host IP port 22: Connection refused

在Linux機器上通常做兩台Server之間的檔案傳輸會使用scp來傳輸資料。
若下scp -r /root/data username@host:/root/data 指令後,出現
ssh: connect to host IP port 22: Connection refused 有以下解法。

安裝openssh

1
2
sudo yum install openssh-client
sudo yum install openssh-server

使用特定Port傳輸

1
2
3
Your ISP may block connections to port 22 (nothing you or your router can do about it). Just set SSHd to run on a different port, e.g. 2222.

In /etc/ssh/sshd_config, change Port 22 to Port 2222 and then sudo service ssh restart. Port forward 2222 (or whatever), and try again.

使用特定Port Example

1
scp -r -P 2222 /root/data username@host:/root/data