Until SSH connection with Fabric (MacOS-> CentOS7)

Ssh connection ready

Create a public key storage

On the server side

mkdir ~/.ssh
chmod 700 ~/.ssh

Make a private / public key

On the local side

ssh-keygen -t <rsa name rsa is OK>
[ENTER]
[Passphrase]
[Confirm passphrase]
chmod 600 ~/.ssh/<rsa name>.pub

Place the public key on the server

Local side

scp ~/.ssh/<rsa name>.pub user@ip:~/.ssh/authorized_keys

sshd settings

Edit the / etc / ssh / sshd_config file

RSAAuthentication yes 
PubkeyAuthentication yes
PasswordAuthentication no
PermitRootLogin no
PasswordAuthentication yes

You may enter prohibition of login as root, password authentication permission, etc.

DenyUsers ALL
AllowUsers <user>

You may not allow connections other than including root. This is an additional setting.

sshd restart

/usr/sbin/sshd -t
systemctl restart sshd.service

Set a private key passphrase

You will be asked for a passphrase every time you connect, so set it

ssh-add <Private key path>

Then, the passphrase will be asked, so enter it.

Fabric preparation

easy_install fabric

(When I was able to use it before but it can no longer be used, I tried raising the version and it worked. It is good to be able to flexibly change the version with pyenv etc.)

Create Fabfile.py

from fabric.api import run

def getHostname():
  run("hostname")

If you created a file with a name other than fabfile.py, enter `-f <fabfile>`. <method>Is for the above filegethostnameIs specified.

fab -H <Server ADDRESS> -u <Server USER> -f <fabfile> <method>

Recommended Posts

Until SSH connection with Fabric (MacOS-> CentOS7)
Do multi-stage SSH with Fabric
Connect to centos6 on virtualbox with ssh connection from Mac
[Note] ssh connection from terminal with AWS LightSail
Introducing Paramiko + scp ~ SSH connection ~ File transfer with SCP
Play with CentOS 8
[GitHub] Until you pull with ssh using Deploy keys
Until Hello World with Flask + uWSGI + Nginx @ Sakura's VPS (CentOS 6.6)