this post was submitted on 13 Nov 2023
17 points (79.3% liked)

Python

5396 readers
1 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

October 2023

November 2023

PastJuly 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
top 6 comments
sorted by: hot top controversial new old
[–] [email protected] 14 points 1 year ago* (last edited 1 year ago) (1 children)

You may want to look at the .ssh/config file in your user directory as a destination to save configuration items. The bonus is that other utilities using ssh get to use the entries you've configured (i.e. scp)

Check out: https://www.man7.org/linux/man-pages/man5/ssh_config.5.html

An example entry in ~/.ssh/config would look like:

Host myserver.net
    User your_username

Then any time you run ssh myserver.net, it'll use the user you specify here by default.

[–] [email protected] 1 points 1 year ago (3 children)

Then any time you run ssh myserver.net, it'll use the user you specify here by default.

Wouldnt really help in my use case bc I use the same user on every server

[–] [email protected] 8 points 1 year ago (1 children)

It was just an example. What does your script do that wouldn't be configurable in ssh config

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

not much, probably. Ill add some features in the future tho

[–] [email protected] 6 points 1 year ago* (last edited 1 year ago)

It's config language is designed for that, too. The following should work:

# Set default username across all hosts
Host *
    User default_username

or

# To match "host1..3"
Match Host host1.example.com host2.example.com host3.example.com
    User default_username

I still think the script is a good idea. I do something similar with a shell script to add entries. Your choice of Python would make maintaining and parsing a lot more straightforward than shell.

[–] [email protected] 2 points 1 year ago

The β€œhost” is just your friendly name for the connection, not necessarily the hostname of the remote host. You can specify the same username or hostname as many times as you want. My config is made up of mostly blocks like this:

Host server1
    HostName server1.you.com
    User your_ssh_username
    IdentityFile ~/.ssh/yourprivatekey.pem
  
Host server2
    HostName server2.you.com
    User your_ssh_username
    IdentityFile ~/.ssh/yourprivatekey.pem