LinuxSSH服务

Posted liang-yao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LinuxSSH服务相关的知识,希望对你有一定的参考价值。

SSH端口:22

linux中守护进程:sshd

安装服务:OpenSSH

服务端主程序:/usr/sbin/sshd

客户端主程序:/usr/bin/ssh

服务端配置文件:/etc/ssh/sshd_conf

Port 22                             #端口

ListenAddress 0.0.0.0      #监听ip

Protocol 2                       #ssh版本

HostKey /etc/ssh/ssh_host_rsa_key  #私钥保存位置

ServerKeyBits 1024        #私钥的位数

SyslogFacility AUTH      #日志记录ssh登陆情况

LogLevel INFO               #日志等级

GSSAPIAuthentication yes               #GSSAPI认证开启

PermitRootLogin yes    #允许root ssh登陆

PubkeyAuthentication yes              #是否使用公钥验证

AuthorizedKeysFile .ssh/authorized_keys #公钥保存位置

PasswordAuthentication yes           #允许密码验证登陆

PermitEmptyPasswords no              #不允许空密码登陆

 

客户端配置文件:/etc/ssh/ssh_conf

 

scp远程复制

上传:# scp -r /root/test.txt [email protected]:/root

下载:# scp [email protected]:/root/test.txt .

 

sftp文件传输

sftp [email protected]

ls           查看服务器端文件

cd         切换到服务端根目录

lls         查看本地文件

lcd       切换本地目录

get      下载

put      上传

 

 密钥登陆

技术分享图片

 

1.client

ssh-keygen -t rsa

把公钥id_rsa.pub上传至服务端

ssh-copy-id [email protected]

2.server

chmod 600 /root/.ssh/authorized_keys

3.server修改服务器端ssh配置文件/etc/ssh/sshd_config

RSAAuthentication yes                                #开启RSA验证

PubkeyAuthentication yes                          #使用公钥验证

AuthorizedKeysFile .ssh/authorized_keys  #公钥位置

PasswordAuthentication no                      #禁止使用密码验证登陆

4.重启sshd服务

systemctl restart sshd.service

注:需要关闭SELinux,否则会提示:Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

windows下使用远程工具导入client的公钥即可

以上是关于LinuxSSH服务的主要内容,如果未能解决你的问题,请参考以下文章

SSH

CentOS 8 启用 ssh 服务

Linux SSH和SFTP服务分离

SSH服务及其扩展(sshpass和expect)

windows10 通过ssh访问 linux

Linux SSH端口更改和SSH远程连接服务慢原因排查