码迷,mamicode.com
首页 > 其他好文 > 详细

9.ssh相关操作

时间:2021-01-18 11:03:05      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:公钥   操作   去掉   authorize   登陆   sshd_conf   vim   执行   test   

ssh远程管理服务

1.1 ssh介绍

ssh远程管理服务

默认linux是安装了的,如果没有安装执行以下命令。
[root@linux-server ~]# yum install -y openssh*
[root@linux-server ~]# systemctl start sshd
openssh-service 提供服务 
openssh-clients 客户端 
sshd服务的端口号  22

ssh建立连接

ssh root@192.168.17.122

1.2 ssh密钥认证实现无密码登陆

1.生成一对密钥:公钥 + 私钥

[root@linux-server ~]# ssh-keygen #一直回车

2.查看秘钥存放的目录

[root@linux-server ~]# cd /root/.ssh/

文件解释
id_rsa 私钥	id_rsa.pub 公钥	
known_hosts:确认过公钥指纹的可信服务器列表的文件
authorized_keys:授权文件,是传输过公钥到对方服务后会自动重命名生成的

3.拷贝公钥给需要面密登入的机器

[root@linux-server ~]# ssh-copy-id 对方机器ip地址

实现免密登入

1.3 修改端口

[root@linux-server ~]# vim /etc/ssh/sshd_config
#Port 22 	#找到这行将注释去掉,默认是22端口,可修改。
[root@linux-server ~]# systemctl restart sshd	#修改完重启服务
修改过端口,就在远程登入的时候 -p 指定端口
ssh root@目标ip -p 目标端口

1.4 远程拷贝

格式:scp -P 端口号 /源文件 目标地址/路径

[root@linux-server ~]# scp -r -P 666 test/ 目标IP:/root/
参数解释:
谁是远程加谁ip
远程拷贝目标机器改了端口加-P
目录加 -r

1.5 禁止root用户远程登陆

[root@localhost ~]# vim /etc/ssh/sshd_config
找到PermintRootLogin取消注释 默认是允许远程登入为yes,改为no就是不允许
#PermitRootLogin no

保存退出并重启sshd服务
[root@testpm ~]# systemctl restart sshd

9.ssh相关操作

标签:公钥   操作   去掉   authorize   登陆   sshd_conf   vim   执行   test   

原文地址:https://www.cnblogs.com/eba001/p/14287383.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!