Linux Networking: SSH and SCP
Posted on June 1, 2024 (Last modified on June 8, 2024) • 2 min read • 280 wordsMaster SSH and SCP commands in Linux for secure remote access and file transfers, including key-based authentication and managing SSH sessions.
SSH and SCP are essential tools for secure remote access and file transfers in Linux. This guide covers SSH configuration, key-based authentication, and using SCP for file transfers.
Install the OpenSSH server.
sudo apt-get install openssh-serverStart and enable the SSH service.
sudo systemctl start ssh
sudo systemctl enable sshEdit the SSH configuration file.
sudo vim /etc/ssh/sshd_configRestart the SSH service to apply changes.
sudo systemctl restart sshGenerate a new SSH key pair.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"Use ssh-copy-id to copy your public key to the remote server.
ssh-copy-id user@remote_serverConnect to the remote server using key-based authentication.
ssh user@remote_serverUse tmux to manage SSH sessions.
tmux new -s session_nameDetach from the session.
Ctrl-b dReattach to the session.
tmux attach -t session_nameUse screen to manage SSH sessions.
screen -S session_nameDetach from the session.
Ctrl-a dReattach to the session.
screen -r session_nameUse scp to copy files between local and remote systems.
scp local_file user@remote_server:/path/to/destinationUse -r option to transfer directories.
scp -r local_directory user@remote_server:/path/to/destinationUse scp to transfer files between two remote systems.
scp user1@remote1:/path/to/file user2@remote2:/path/to/destinationMastering SSH and SCP commands is essential for secure remote access and file transfers in Linux. Practice configuring SSH, setting up key-based authentication, and using SCP for file transfers to enhance your networking skills.