解决 ssh: connect to host xxx port 22: Connection refused&& Failed to restart sshd.service: Unit ssh.

1.安装 ssh server

sudo apt-get install openssh-server

sudo apt-get install openssh-client

2.查看 ssh 状态

sudo systemctl status  ssh

* ssh.service
   Loaded: masked (/dev/null; bad)
   Active: failed (Result: exit-code) since Fri 2019-04-12 14:45:09 CST; 1min 22s ago
 Main PID: 7966 (code=exited, status=255)

Apr 12 14:45:09 yy-pc systemd[1]: Starting OpenBSD Secure Shell server...
Apr 12 14:45:09 y-pc sshd[7966]: error: Bind to port 25 on 0.0.0.0 failed: Address already in use.
Apr 12 14:45:09 y-pc sshd[7966]: error: Bind to port 25 on :: failed: Address already in use.
Apr 12 14:45:09 y-pc sshd[7966]: fatal: Cannot bind any address.
Apr 12 14:45:09 y-pc systemd[1]: ssh.service: Main process exited, code=exited, status=255/n/a
Apr 12 14:45:09 y-pc systemd[1]: ssh.service: Failed with result 'exit-code'.
Apr 12 14:45:09 y-pc systemd[1]: Failed to start OpenBSD Secure Shell server.


3.修改 config 文件

sudo vi /etc/ssh/sshd_config

ssh 默认 22端口

打开注释掉的或者加上

Port 22

 

4. 重启ssh server

service sshd restart

出现了这个小问题:

Failed to restart ssh.service: Unit ssh.service is masked.

sudo systemctl unmask sshs

service sshd restart

sudo systemctl status  ssh

状态正常:

* ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-04-12 14:48:29 CST; 7min ago
  Process: 8276 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Main PID: 8277 (sshd)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/ssh.service
           `-8277 /usr/sbin/sshd -D

Apr 12 14:48:29 y-pc systemd[1]: Starting OpenBSD Secure Shell server...
Apr 12 14:48:29 y-pc sshd[8277]: Server listening on 0.0.0.0 port 22.
Apr 12 14:48:29 y-pc sshd[8277]: Server listening on :: port 22.
Apr 12 14:48:29 y-pc systemd[1]: Started OpenBSD Secure Shell server.
Apr 12 14:48:47 y-pc sshd[8285]: Authentication refused: bad ownership or modes for directory /home/yq
Apr 12 14:48:50 y-pc sshd[8285]: Accepted password for yq from 127.0.0.1 port 60136 ssh2
Apr 12 14:48:50 y-pc sshd[8285]: pam_unix(sshd:session): session opened for user yq by (uid=0)
Apr 12 14:49:02 y-pc sshd[8408]: Accepted password for yq from 192.168.20.194 port 1089 ssh2
Apr 12 14:49:02 y-pc sshd[8408]: pam_unix(sshd:session): session opened for user yq by (uid=0)

 

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值