ssh服务器(自己的一点心得和操作总结)

ssh服务器的架构

  • 1.安装ssh服务器

sudo apt-get install openssh-server

查看ssh服务器是否安装成功:

 ssh -V
  • 2.查看ssh配置文件:vim /etc/ssh/sshd_config

用vim进行编辑:

设置成如下:

# Authentication:
LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no


其中,主要是:

PermitEmptyPasswords no
PermitRootLogin prohibit-password

使得无密码通过或者是按照服务器的密码登录

  • 用ssh客户端登录:

ssh 本机ip/hostname
  • 以超级管理员身份登录:
ssh root@hostname



当第一次登陆某服务器时:

会出现这些代码:

The authenticity of host 'foo.com (192.168.121.111)' can't be established.
ECDSA key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY.
Are you sure you want to continue connecting (yes/no)?

这时候出现的这个是我们所谓的密钥,同时,不同的算法对应不同的密码与密钥(密码学拓展)

那么这里如果光输入"yes" 然后再进行进一步的操作——也就是输入你的服务器密码时,是不会接通的。

我们将出现过的这个东西:

ECDSA key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY.
  • 称为指纹

类比于指纹,这是一个新的指纹,如何让它能够解锁:

那当然是将它加入到你的指纹中啦,也就是给予它信任:

$ ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub
256 da:24:43:0b:2e:c1:3f:a1:84:13:92:01:52:b4:84:ff   (ECDSA)

上面的例子中,ssh-keygen -l -f命令会输出公钥/etc/ssh/ssh_host_ecdsa_key.pub的指纹。

ssh 会将本机连接过的所有服务器公钥的指纹,都储存在本机的~/.ssh/known_hosts文件中。每次连接服务器时,通过该文件判断是否为陌生主机(陌生公钥)。

在上面这段文字后面,输入yes,就可以将当前服务器的指纹也储存在本机~/.ssh/known_hosts文件中,并显示下面的提示。以后再连接的时候,就不会再出现警告了。

Warning: Permanently added 'foo.com (192.168.121.111)' (RSA) to the list of known hosts




可能会出现的问题:

ssh: connect to host 192.168.241.128 port 22: Connection refused
  • 解决方法:是因为没有打开ssh服务:

    我们用这个命令查看:

service ssh status

得到的结果:

ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; disabled; vendor preset: disabled)
     Active: inactive (dead)
       Docs: man:sshd(8)
             man:sshd_config(5)
  • 我们发现这一行:
Active: inactive (dead) #状态:inactive

那么也就是我们需要激活ssh服务

service ssh start

启用ssh服务后:再一次运行

service ssh status

这次得到的结果:

ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; disabled; vendor preset: disabled)
     Active: active (running) since Thu 2020-12-24 06:58:16 EST; 2s ago
       Docs: man:sshd(8)
             man:sshd_config(5)
  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值