linux基础-ssh服务
SSH
ssh 服务是实现管路服务器的一种方式: 本地管理(安装系统,故障修复),ssh 远程连接
linux 可以是实现远程连接的方式:ssh 命令
windows 可以实现远程连接方式: xshell 、 xmanager 、putty、moba
ssh 的认证方式: 基于用户名、密码、密钥
基于密钥的配置:
在客户端生成密钥对
把公钥发送给服务器
linux 提供ssh 服务/ssh 客户端的软件:
[root@localhost ~]# rpm -qa | grep ssh
openssh-7.4p1-11.el7.x86_64
openssh-clients-7.4p1-11.el7.x86_64
openssh-server-7.4p1-11.el7.x86_64
[root@localhost ~]# ss -antp | grep sshd
LISTEN 0 128 *:22 *:* users:(("sshd",pid=1113,fd=3))
LISTEN 0 128 127.0.0.1:6010 *:* users:(("sshd",pid=2084,fd=9))
ESTAB 0 0 192.168.40.100:22 192.168.40.149:62515 users:(("sshd",pid=2415,fd=3))
ESTAB 0 0 192.168.40.100:22 192.168.40.149:62511 users:(("sshd",pid=2084,fd=3))
LISTEN 0 128 :::22 :::* users:(("sshd",pid=1113,fd=4))
LISTEN 0 128 ::1:6010 :::* users:(("sshd",pid=2084,fd=8))
远程连接主机
ssh + ip地址(如果做了域名解析,可直接ssh 主机名)
[root@localhost ~]# ssh 192.168.40.100
ssh + 地址 + 执行的操作
[root@localhost ~]# ssh 192.168.40.100 'hostname'
root@192.168.40.100's password:
server-1
ssh 配置文件
配置文件:/etc/ssh/sshd_config
1) 关闭SSH对主机名的解析
GSSAPIAuthentication no
UseDNS no
[root@node1 ~]# systemctl restart sshd
2) 禁用root用户远程连接
PermitRootLogin no --(root用户不能远程登录,如果想让root用户可以远程登录设置为yes)
3) 修改默认的SSH端口
Port 22345
ListenAddress 192.168.122.121
关于密钥的设置
在服务器上生成密钥
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:JHnfdLBZthSBhlrujBKsQj+xZFlAktroj39l/PcdXhE root@server-1
The key's randomart image is:
+---[RSA 2048]----+
| .oo. ...*o |
| .. .. o oB . |
| + +o o+ .+ oE |
|o o = o+...o . .|
|.. + +..S+. . . |
| .. = .+. o .|
| o. .o.. ..|
| . . . . . o o|
| ... . .. o |
+----[SHA256]-----+
[root@localhost ~]# ls .ssh/
id_rsa id_rsa.pub known_hosts
id_rsa 私钥
id_rsa.pub 公钥
如果将本地生成的公钥拷贝到目的主机上下次登录不用输入密码
[root@localhost ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.40.100
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.40.100's password:
最新文章
- 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划
- 从github下载某个git库的4种方法
- Rhel6-cacti+nagios+ganglia(nginx)配置文档
- PHP里用户密码的回复和管理
- 解决xcode打开时loading假死的问题
- 知识点整理之Java的Cookie操作
- C#堆栈原理(我有两个例子测试你到底会不会)
- linux之SQL语句简明教程---SELECT
- API和DLL
- sublime学习笔记
- ORACLE透明网关访问SQL Server配置总结
- iOS presentViewController 方法引起的问题
- Zabbix调优不完全指南(https://www.jianshu.com/p/2d911d55448f)
- C#常用工具类——Excel操作类(ZT)
- HTML_CSS笔记
- 洛谷P4561 [JXOI2018]排序问题(二分 期望)
- 最全的jquery datatables api 使用详解
- MATLAB变量
- 将Highcharts图表数据生成Table表格
- hdu 1556 A - Color the ball 其他做法
热门文章
- 【转】Redis面试题
- Springboot上传图片并访问
- CentOS7 安装 anaconda
- Note | PyTorch1.2 + CUDA10.0 + cuDNN7.6 + Anaconda3配置
- python-3-条件判断练习题
- 小程序开发笔记(八)—Js数组按日期分组显示数据
- Netty服务端的启动源码分析
- 带你认识MySQL sys schema
- 使用AvalonEdit实现WPF的Lua编辑器
- laravel he stream or file ";..laravel-2019-02-14.log"; could not be opened: failed to open stream: Permission denied