天天看點

linux服務ssh詳解

ssh服務:

管理伺服器的方式:

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

SSH遠端連接配接的方式

Linux: ssh指令

Windows:

Xshell;  Xmanager

SecureCRT

Putty 

提供ssh服務/ssh用戶端工具的軟體:

[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))

1、遠端連接配接主機 

# ssh [user@]host 

# ssh 192.168.87.10

# ssh [email protected] 

2、遠端連接配接主機執行指令 

# ssh 192.168.87.10 'hostname' 

[root@localhost ~]# ssh [email protected] 'hostname'

3、遠端複制檔案的工具 

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 [email protected] -p 22345

關閉SELinux和防火牆

# setenforce 0

# vim /etc/sysconfig/selinux 

關閉防火牆 

# systemctl stop firewalld

# systemctl disable firewalld

SSH認證方式:

基于使用者名、密碼;預設 

基于密鑰

基于密鑰的配置方法:

1、在用戶端生成密鑰對 

2、把公鑰傳送給伺服器 

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

本文轉自 北冥有大魚  51CTO部落格,原文連結:http://blog.51cto.com/lyw168/1957475,如需轉載請自行聯系原作者