mac 下配置连接Linux服务器方法,上传下载文件操作

时间:2023-03-08 16:16:12

1、先按照文档在本地生成SSHkey

2、mac输入 sudo -i 进入超级管理员#模式下,然后

创建用户
#useradd XXXadmin
#passwd XXXadmin

XXXadmin用户增加授权key
cd /home/XXXadmin/
mkdir .ssh
chmod 700 ~/.ssh
把本地的key :XXXadmin.pub上传到 .ssh 下 并重命名为:authorized_keys
chmod 600 authorized_keys

修改用户组
chown -R XXXadmin:XXXadmin ./.ssh

编辑ssh 配置文件
vi /etc/ssh/sshd_config
去掉下面三行注释
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
修改
Port 5555
PermitRootLogin no
PasswordAuthentication no //禁止使用密码登录
service sshd restart

~~~~~~~~上传文件到服务器,下载服务器文件到本地~~~~~~

1.本文主要是采用scp 来进行复制

abc@abcs-Mac:~$ scp -h
scp: illegal option -- h
usage: scp [-346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 ... [[user@]host2:]file2

OPTIONS:

-v 和大多数 linux命令中的-v意思一样,用来显示进度。可以用来查看连接、认证、或是配置错误

-C 使能压缩选项

-P 选择端口

-r 复制目录

1、从本地将文件传输到服务器

scp【本地文件的路径】【服务器用户名】@【服务器地址】:【服务器上存放文件的路径】

abc@abcs-Mac:~$ scp -P  /Applications/program/HTTP请求.jmx lilyadmin@xxx.xx.xx.xxx:/home/lilyadmin/
HTTP请求.jmx % .4KB/s :

2、从本地将文件夹传输到服务器

scp -r【本地文件的路径】【服务器用户名】@【服务器地址】:【服务器上存放文件的路径】

scp -r -P  /Applications/program/test11 lilyadmin@106.xxx.xx.xxx:/home/lilyadmin/

3、将服务器上的文件传输到本地

scp 【服务器用户名】@【服务器地址】:【服务器上存放文件的路径】【本地文件的路径】

 scp -v -P 5555 lilyadmin@xxx.xx.xx.xxx:/home/lilyadmin/1.txt /Users/abc/

4、将服务器上的文件夹传输到本地

scp -r 【服务器用户名】@【服务器地址】:【服务器上存放文件的路径】【本地文件的路径】

 scp -r -v -P  lilyadmin@xxx.xx.xx.xxx:/home/lilyadmin/test /Users/abc/
Executing: program /usr/bin/ssh host 106.xxx.xx.xxx, user lilyadmin, command scp -v -f /home/lilyadmin/.txt
OpenSSH_7.6p1, LibreSSL 2.6.
debug1: Reading configuration data /etc/ssh/ssh_config #读取配置文件
debug1: /etc/ssh/ssh_config line : Applying options for *
debug1: Connecting to 106.xx.xxx.xxx port .
debug1: Connection established.
debug1: identity file /Users/abc/.ssh/id_rsa type
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_rsa-cert type -
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_dsa type -
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_dsa-cert type -
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_ecdsa type -
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_ecdsa-cert type -
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_ed25519 type -
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_ed25519-cert type -
debug1: Local version string SSH-2.0-OpenSSH_7.
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.
debug1: match: OpenSSH_5. pat OpenSSH_5* compat 0x0c000000
debug1: Authenticating to 106.xxx.xx.xxx: as 'lilyadmin'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: umac-@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-@openssh.com compression: none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(<<) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:2qZOXDtbDTclZAu6pdw/WMa8Xd0T/9LI+/beV7sR92U
debug1: Host '[106.xx.xx.xxx]:5555' is known and matches the RSA host key.
debug1: Found key in /Users/abc/.ssh/known_hosts:
debug1: rekey after blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:+crvOvxCiUncwpe2N5atQJAeCJgqeomHV1H0QVKgJGc /Users/abc/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen
debug1: Authentication succeeded (publickey).
Authenticated to 106.xx.xx.xxx ([106.xx.xx.xxx]:).
debug1: channel : new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = zh_CN.UTF-
debug1: Sending command: scp -v -f /home/lilyadmin/.txt
Sending file modes: C0644 .txt
Sink: C0644 .txt
.txt % .0KB/s :
debug1: client_input_channel_req: channel rtype exit-status reply
debug1: client_input_channel_req: channel rtype eow@openssh.com reply
debug1: channel : free: client-session, nchannels
debug1: fd clearing O_NONBLOCK
debug1: fd clearing O_NONBLOCK
Transferred: sent , received bytes, in 0.1 seconds
Bytes per second: sent 50227.8, received 45639.1
debug1: Exit status