远程连接和SSH

ifconfig 和 ip addr 查看IP信息。ifconfig为net-tools中的命令,ip addr为iproute2中的命令

配置SSH服务
1)安装openssh
  1-1)客户端:openssh-client
      sudo yum install openssh-clients
  1-2)服务端:openssh-server
      sudo yum install openssh-server
2) 安装完服务端后会自动开启sshd精灵进程(守护进程),是运行在后台的特殊进程。
  手动开启时:sudo systemctl start sshd
  停止sshd服务:sudo systemctl stop sshd
  重启sshd服务: sudo systemctl restart sshd
  查看sshd的状态:sudo systemctl status sshd
  将sshd设为开机自启动:sudo systemctl enable sshd

查看所有开机自启动:
  systemctl list-unit-files | grep enabled

客户端连接服务端:
 ssh [email protected]

配置config文件
服务端:/etc/ssh/sshd_config
客户端:/etc/ssh/ssh_config
        ~/.ssh/config
注:服务端,如果root用户Home目录下没有.ssh目录,可以使用ssh localhost命令生成.ssh目录。配置后需要重启sshd服务
    客户端一般没有config文件,需要手动创建,创建后把权限改为600
     touch config
     chmod 600 ~/.ssh/config
客户端配置 config
Host annier #别名
    HostName 127.0.0.1 #服务器IP地址
    Port 22 #商口号
    User root #登陆名
配置后可直接使用ssh annier 命令连接服务器

公钥验证登录 ( 免密码登录)
1)在客户机中生成密钥对(公钥和私钥)
    ssh-keygen(默认使用RSA非对称加密算法)等效于:ssh-keygen -t rsa 
   命令运行后会在~/.ssh/目录下生成两个文件
    id_rsa.pub:公钥
    id_rsa :私钥
2)把客户机的公钥传送到服务器
   ssh-copy-id [email protected] 等效于ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected]
  命令会把客户机的公钥追加到服务器的~/.ssh/authorized_keys文件中

注:ssh -o PreferredAuthentications=password -o PubkyeAuthentication=no [email protected] 命令可以重新回到密码登录
    

猜你喜欢

转载自www.cnblogs.com/tngh/p/13397318.html
今日推荐