linux登录远程服务器及scp命令传输文件(ssh(Connection refused lost connection) 错误),及centos7.3防火墙操作

登录远程服务器需要指定ssh开放的端口号,一般在购买远程服务器上会有显示:ssh -p端口号 登录账号名称(一般是root)@远程服务器ip,然后它会提示你输入密码

scp命令传输文件时要指定开放的端口号,否则它默认的22端口是拒绝连接的。(错误示范)
scp -r /home/lin/Desktop/adslproxy/ [email protected]:/home/download

lin@ubuntu:~/Desktop/git$ scp -r /home/lin/Desktop/adslproxy/ root@xx.xx.xx.xx:/home/download
ssh: connect to host xx.xx.xx.xx port 22: Connection refused
lost connection

scp指定端口号传输文件

scp -r -P端口号 /home/lin/Desktop/adslproxy/ root@xx.xx.xx.xx:/home/download
root@xx.xx.xx.xx's password: 
config.py                                     100%  578     0.6KB/s   00:00    
__init__.py                                   100%  147     0.1KB/s   00:00    
db.cpython-36.pyc                             100% 2622     2.6KB/s   00:00    
config.cpython-36.pyc                         100%  475     0.5KB/s   00:00    
__init__.cpython-36.pyc                       100%  346     0.3KB/s   00:00    
api.cpython-36.pyc                            100% 1505     1.5KB/s   00:00    
sender.cpython-36.pyc                         100% 3019     3.0KB/s   00:00    
sender.py                                     100% 3039     3.0KB/s   00:00    
api.py                                        100% 1508     1.5KB/s   00:00    
db.py                                         100% 1926     1.9KB/s   00:00    

由于预装系统是centos7.3,防火墙操作命令与linux还是有些区别
1、查看防火墙服务状态 systemctl status firewalld

[root@localhost download]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)

2、查看防火墙运行状态(是否开启关闭)firewall-cmd –state

[root@localhost download]# firewall-cmd --state
running

3、关闭防火墙 service firewalld stop

[root@localhost download]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service

4、开启防火墙service firewalld start

[root@localhost download]# service firewalld start
Redirecting to /bin/systemctl start firewalld.service

5、重启防火墙 service firewalld restart

[root@localhost download]# service firewalld restart
Redirecting to /bin/systemctl restart firewalld.service

6、查看开放端口 firewall-cmd –list-all

trusted (active)
  target: ACCEPT
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: 
  ports: 8888/tcp   #这里开放了8888端口
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

7、开放指定端口[root@localhost download]# firewall-cmd –permanent –add-port=22/tcp 这里的22是要开放的端口

[root@localhost download]# firewall-cmd --permanent --add-port=22/tcp
success

8、关闭指定端口 firewall-cmd –permanent –remove-port=22/tcp

[root@localhost download]# firewall-cmd --permanent --remove-port=22/tcp
success

9、重启防火墙(开启或关闭防火墙后需要重启才能生效)firewall-cmd –reload

[root@localhost download]# firewall-cmd --reload
success

你可能感兴趣的:(linux登录远程服务器及scp命令传输文件(ssh(Connection refused lost connection) 错误),及centos7.3防火墙操作)