Ubuntu环境下SSH的安装及使用

本文介绍ubuntu 上安装使用ssh ,以及windows 登录ubuntu 使用ssh

客户端

安装:

sudo apt-get install ssh  或者 

sudo apt-get install openssh-client

使用:

ssh remote_host 或者

ssh remote_username@remote_host

服务端

安装命令:

sudo apt-get install openssh-server

检查是否安装好:

ps -e|grep ssh

启动:

sudo systemctl start ssh

停止

sudo systemctl stop ssh

配置:

如果要改变,要先备份 sudo cp /etc/ssh/sshd_config{,.bak}

然后编辑  sudo nano /etc/ssh/sshd_config

配置生效

sudo systemctl reload ssh

需要系统启动时启动 ssh:

 sudo systemctl enable ssh

如果要取消系统启动时启动ssh:

 sudo systemctl disable ssh

查看ssh状态

leon@leon-desktop:/etc/ssh$ 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 Wed 2021-03-31 15:18:04 EDT; 8h ago
 Main PID: 930 (sshd)
    Tasks: 1 (limit: 1056)
   CGroup: /system.slice/ssh.service
           └─930 /usr/sbin/sshd -D

Mar 31 15:18:09 leon-desktop systemd[1]: Reloaded OpenBSD Secure Shell server.
Mar 31 15:18:09 leon-desktop sshd[930]: Server listening on 0.0.0.0 port 22.
Mar 31 15:18:09 leon-desktop sshd[930]: Server listening on :: port 22.
Mar 31 15:18:29 leon-desktop sshd[1387]: Accepted password for leon from 192.168.2.49 port 52200 ssh2
Mar 31 15:18:29 leon-desktop sshd[1387]: pam_unix(sshd:session): session opened for user leon by (uid=0)
Mar 31 23:14:31 leon-desktop systemd[1]: Reloading OpenBSD Secure Shell server.
Mar 31 23:14:32 leon-desktop sshd[930]: Received SIGHUP; restarting.
Mar 31 23:14:32 leon-desktop systemd[1]: Reloaded OpenBSD Secure Shell server.
Mar 31 23:14:32 leon-desktop sshd[930]: Server listening on 0.0.0.0 port 

故障排除 ,这是客户端无法登录,状态显示key 问题,参考: https://ubuntu-mate.community/t/ssh-server-on-18-04-beta-1-pi/19245

sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key

sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key

sudo ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

执行上面3个,生成key 后就可以登录了,状态也正常了。

windows 登录

下载并运行putty

输入 主机地址就可

其他

查看主机地址:

ip a s

其实是 ip address show

leon@leon-desktop:/etc/ssh$ ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether b8:27:eb:dd:c2:f6 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether b8:27:eb:88:97:a3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.80/24 brd 192.168.2.255 scope global dynamic noprefixroute wlan0
       valid_lft 229478sec preferred_lft 229478sec
    inet6 fe80::8cc7:5af7:620b:2fda/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
leon@leon-desktop:/etc/ssh$

查看局域网上的 ip 地址 windows和ubuntu 上都可以用

leon@leon-desktop:/etc/ssh$ arp -a
? (192.168.2.49) at 8c:70:5a:54:dc:58 [ether] on wlan0
? (192.168.2.74) at e4:e4:ab:23:91:23 [ether] on wlan0
? (192.168.2.78) at 38:1a:52:12:95:fa [ether] on wlan0
_gateway (192.168.2.1) at 3c:17:10:2e:48:58 [ether] on wlan0
leon@leon-desktop:/etc/ssh$

怎么用key 登录,看 https://www.digitalocean.com/community/tutorials/how-to-use-ssh-to-connect-to-a-remote-server

我还没看懂。

介绍这么多,谢阅读。

 

 

 

 

 

 

上一篇:Openssh


下一篇:CF1009F Dominant Indices