linux服務ssh詳解

ssh服務:node

管理服務器的方式:linux

本地管理 (安裝系統、故障修復)shell

SSH遠程鏈接的方式vim

Linux: ssh命令服務器

Windows:ssh

Xshell; Xmanager ide

SecureCRT工具

Putty spa


提供ssh服務/ssh客戶端工具的軟件:rest


[root@localhost ~]# rpm -qa | grep ssh

openssh-server-6.6.1p1-33.el7_3.x86_64

openssh-clients-6.6.1p1-33.el7_3.x86_64


[root@localhost ~]# systemctl status sshd    ------>查狀態


[root@localhost ~]# ss -antp | grep sshd

LISTEN     0      128          *:22                       *:*                   users:(("sshd",pid=1202,fd=3))


一、遠程鏈接主機 


# ssh [user@]host 

# ssh 192.168.87.10

# ssh marin@192.168.87.10 

二、遠程鏈接主機執行命令 


# ssh 192.168.87.10 'hostname' 


[root@localhost ~]# ssh martin@192.168.122.105 'hostname'




三、遠程複製文件的工具 


scp, rsync (增量複製)


[root@node01 ~]# scp /etc/fstab 192.168.122.121:/tmp/


[root@node01 ~]# scp 192.168.122.121:/etc/passwd /tmp/


-r:複製目錄


rsync


[root@node01 ~]# rsync -av /bj/ 192.168.122.121:/sh


[root@node01 ~]# rsync -av /bj 192.168.122.121:/sh



配置文件:/etc/ssh/sshd_config 


1) 關閉SSH對主機名的解析 


GSSAPIAuthentication no

UseDNS no


[root@node1 ~]# systemctl restart sshd 



2) 禁用root用戶遠程鏈接 


PermitRootLogin no


3) 修改默認的SSH端口 


Port 22345

ListenAddress 192.168.122.121


[root@server ~]# ssh martin@192.168.87.10 -p 22345



關閉SELinux和防火牆


# setenforce 0

# vim /etc/sysconfig/selinux 


關閉防火牆 


# systemctl stop firewalld

# systemctl disable firewalld


SSH認證方式:


基於用戶名、密碼;默認 

基於密鑰

基於密鑰的配置方法:

一、在客戶端生成密鑰對 

二、把公鑰傳送給服務器 



1) 在客戶端生成密鑰對

 

[root@server ~]# ssh-keygen -t rsa


[root@server ~]# ls .ssh/

id_rsa  id_rsa.pub  known_hosts


id_rsa 私鑰

id_rsa.pub 公鑰



2) 把公鑰傳送給服務器


[root@server ~]# ssh-copy-id -i -p 22345 192.168.87.10

相關文章
相關標籤/搜索